Documentation ¶
Index ¶
- Constants
- func GetTLSCertFromFile(path string) (*tls.Certificate, error)
- type BlackholeClient
- type BrokerConfig
- type Client
- type ConfigWrapper
- type Event
- type KafkaClient
- type PublishBuilder
- func (p *PublishBuilder) AdditionalFields(additionalFields map[string]interface{}) *PublishBuilder
- func (p *PublishBuilder) ClientID(clientID string) *PublishBuilder
- func (p *PublishBuilder) ClientIDs(clientIDs []string) *PublishBuilder
- func (p *PublishBuilder) Context(ctx context.Context) *PublishBuilder
- func (p *PublishBuilder) ErrorCallback(errorCallback func(event *Event, err error)) *PublishBuilder
- func (p *PublishBuilder) EventID(eventID int) *PublishBuilder
- func (p *PublishBuilder) EventLevel(eventLevel int) *PublishBuilder
- func (p *PublishBuilder) EventName(eventName string) *PublishBuilder
- func (p *PublishBuilder) EventType(eventType int) *PublishBuilder
- func (p *PublishBuilder) Namespace(namespace string) *PublishBuilder
- func (p *PublishBuilder) Payload(payload map[string]interface{}) *PublishBuilder
- func (p *PublishBuilder) Privacy(privacy bool) *PublishBuilder
- func (p *PublishBuilder) ServiceName(serviceName string) *PublishBuilder
- func (p *PublishBuilder) SessionID(sessionID string) *PublishBuilder
- func (p *PublishBuilder) SpanContext(spanID string) *PublishBuilder
- func (p *PublishBuilder) TargetNamespace(targetNamespace string) *PublishBuilder
- func (p *PublishBuilder) TargetUserIDs(targetUserIDs []string) *PublishBuilder
- func (p *PublishBuilder) Topic(topics ...string) *PublishBuilder
- func (p *PublishBuilder) TraceID(traceID string) *PublishBuilder
- func (p *PublishBuilder) UserID(userID string) *PublishBuilder
- func (p *PublishBuilder) Version(version int) *PublishBuilder
- type StdoutClient
- type SubscribeBuilder
- func (s *SubscribeBuilder) Callback(callback func(ctx context.Context, event *Event, err error) error) *SubscribeBuilder
- func (s *SubscribeBuilder) Context(ctx context.Context) *SubscribeBuilder
- func (s *SubscribeBuilder) EventName(eventName string) *SubscribeBuilder
- func (s *SubscribeBuilder) GroupID(groupID string) *SubscribeBuilder
- func (s *SubscribeBuilder) Offset(offset int64) *SubscribeBuilder
- func (s *SubscribeBuilder) Topic(topic string) *SubscribeBuilder
Constants ¶
const ( OffLevel = "off" InfoLevel = "info" DebugLevel = "debug" WarnLevel = "warn" ErrorLevel = "error" )
log level
const (
DefaultSSLCertPath = "/etc/ssl/certs/ca-certificates.crt" // Alpine certificate path
)
Variables ¶
This section is empty.
Functions ¶
func GetTLSCertFromFile ¶
func GetTLSCertFromFile(path string) (*tls.Certificate, error)
GetTLSCertFromFile reads file, divides into key and certificates
Types ¶
type BlackholeClient ¶
type BlackholeClient struct{}
BlackholeClient satisfies the publisher for mocking
func (*BlackholeClient) Publish ¶
func (client *BlackholeClient) Publish(publishBuilder *PublishBuilder) error
func (*BlackholeClient) Register ¶
func (client *BlackholeClient) Register(subscribeBuilder *SubscribeBuilder) error
type BrokerConfig ¶
type BrokerConfig struct { LogMode string StrictValidation bool CACertFile string DialTimeout time.Duration ReadTimeout time.Duration WriteTimeout time.Duration }
BrokerConfig is custom configuration for message broker
type Client ¶
type Client interface { Publish(publishBuilder *PublishBuilder) error Register(subscribeBuilder *SubscribeBuilder) error }
Client is an interface for event stream functionality
type ConfigWrapper ¶
type ConfigWrapper struct { Writer *kafka.Writer // contains filtered or unexported fields }
type Event ¶
type Event struct { ID string `json:"id"` EventName string `json:"name"` Namespace string `json:"namespace"` ClientID string `json:"clientId"` TraceID string `json:"traceId"` SpanContext string `json:"spanContext"` UserID string `json:"userId"` SessionID string `json:"sessionId"` Timestamp string `json:"timestamp"` Version int `json:"version"` EventID int `json:"event_id"` EventType int `json:"event_type"` EventLevel int `json:"event_level"` ServiceName string `json:"service"` ClientIDs []string `json:"client_ids"` TargetUserIDs []string `json:"target_user_ids"` TargetNamespace string `json:"target_namespace"` Privacy bool `json:"privacy"` Topic string `json:"topic"` AdditionalFields map[string]interface{} `json:"additional_fields,omitempty"` Payload map[string]interface{} `json:"payload"` }
Event defines the structure of event
func ConstructEvent ¶
func ConstructEvent(publishBuilder *PublishBuilder) (kafka.Message, *Event, error)
ConstructEvent construct event message
type KafkaClient ¶
type KafkaClient struct {
// contains filtered or unexported fields
}
KafkaClient wraps client's functionality for Kafka
func (*KafkaClient) Publish ¶
func (client *KafkaClient) Publish(publishBuilder *PublishBuilder) error
Publish send event to single or multiple topic with exponential backoff retry
func (*KafkaClient) Register ¶
func (client *KafkaClient) Register(subscribeBuilder *SubscribeBuilder) error
Register register callback function and then subscribe topic nolint: gocognit,funlen
type PublishBuilder ¶
type PublishBuilder struct {
// contains filtered or unexported fields
}
PublishBuilder defines the structure of message which is sent through message broker
func (*PublishBuilder) AdditionalFields ¶
func (p *PublishBuilder) AdditionalFields(additionalFields map[string]interface{}) *PublishBuilder
AdditionalFields set AdditionalFields of publisher event
func (*PublishBuilder) ClientID ¶
func (p *PublishBuilder) ClientID(clientID string) *PublishBuilder
ClientID set clientID of publisher event
func (*PublishBuilder) ClientIDs ¶
func (p *PublishBuilder) ClientIDs(clientIDs []string) *PublishBuilder
ClientIDs set clientIDs of publisher event
func (*PublishBuilder) Context ¶
func (p *PublishBuilder) Context(ctx context.Context) *PublishBuilder
Context define client context when publish event. default: context.Background()
func (*PublishBuilder) ErrorCallback ¶
func (p *PublishBuilder) ErrorCallback(errorCallback func(event *Event, err error)) *PublishBuilder
ErrorCallback function to handle the event when failed to publish
func (*PublishBuilder) EventID ¶
func (p *PublishBuilder) EventID(eventID int) *PublishBuilder
EventID set eventID of publisher event
func (*PublishBuilder) EventLevel ¶
func (p *PublishBuilder) EventLevel(eventLevel int) *PublishBuilder
EventLevel set eventLevel of publisher event
func (*PublishBuilder) EventName ¶
func (p *PublishBuilder) EventName(eventName string) *PublishBuilder
EventName set name of published event
func (*PublishBuilder) EventType ¶
func (p *PublishBuilder) EventType(eventType int) *PublishBuilder
EventType set eventType of publisher event
func (*PublishBuilder) Namespace ¶
func (p *PublishBuilder) Namespace(namespace string) *PublishBuilder
Namespace set namespace of published event
func (*PublishBuilder) Payload ¶
func (p *PublishBuilder) Payload(payload map[string]interface{}) *PublishBuilder
Payload is a event payload that will be published
func (*PublishBuilder) Privacy ¶
func (p *PublishBuilder) Privacy(privacy bool) *PublishBuilder
Privacy set privacy of publisher event
func (*PublishBuilder) ServiceName ¶
func (p *PublishBuilder) ServiceName(serviceName string) *PublishBuilder
ServiceName set serviceName of publisher event
func (*PublishBuilder) SessionID ¶
func (p *PublishBuilder) SessionID(sessionID string) *PublishBuilder
SessionID set sessionID of publisher event
func (*PublishBuilder) SpanContext ¶
func (p *PublishBuilder) SpanContext(spanID string) *PublishBuilder
SpanContext set jaeger spanContext of publisher event
func (*PublishBuilder) TargetNamespace ¶
func (p *PublishBuilder) TargetNamespace(targetNamespace string) *PublishBuilder
TargetNamespace set targetNamespace of publisher event
func (*PublishBuilder) TargetUserIDs ¶
func (p *PublishBuilder) TargetUserIDs(targetUserIDs []string) *PublishBuilder
TargetUserIDs set targetUserIDs of publisher event
func (*PublishBuilder) Topic ¶
func (p *PublishBuilder) Topic(topics ...string) *PublishBuilder
Topic set channel / topic name
func (*PublishBuilder) TraceID ¶
func (p *PublishBuilder) TraceID(traceID string) *PublishBuilder
TraceID set traceID of publisher event
func (*PublishBuilder) UserID ¶
func (p *PublishBuilder) UserID(userID string) *PublishBuilder
UserID set userID of publisher event
func (*PublishBuilder) Version ¶
func (p *PublishBuilder) Version(version int) *PublishBuilder
Version set event schema version
type StdoutClient ¶
type StdoutClient struct {
// contains filtered or unexported fields
}
StdoutClient satisfies the publisher for mocking
func (*StdoutClient) Publish ¶
func (client *StdoutClient) Publish(publishBuilder *PublishBuilder) error
Publish print event to console
func (*StdoutClient) Register ¶
func (client *StdoutClient) Register(subscribeBuilder *SubscribeBuilder) error
Register print event to console
type SubscribeBuilder ¶
type SubscribeBuilder struct {
// contains filtered or unexported fields
}
SubscribeBuilder defines the structure of message which is sent through message broker
func NewSubscribe ¶
func NewSubscribe() *SubscribeBuilder
NewSubscribe create new SubscribeBuilder instance
func (*SubscribeBuilder) Callback ¶
func (s *SubscribeBuilder) Callback( callback func(ctx context.Context, event *Event, err error) error, ) *SubscribeBuilder
Callback to do when the event received
func (*SubscribeBuilder) Context ¶
func (s *SubscribeBuilder) Context(ctx context.Context) *SubscribeBuilder
Context define client context when subscribe event. default: context.Background()
func (*SubscribeBuilder) EventName ¶
func (s *SubscribeBuilder) EventName(eventName string) *SubscribeBuilder
EventName set event name that will be subscribe
func (*SubscribeBuilder) GroupID ¶
func (s *SubscribeBuilder) GroupID(groupID string) *SubscribeBuilder
GroupID set subscriber groupID or queue group name
func (*SubscribeBuilder) Offset ¶
func (s *SubscribeBuilder) Offset(offset int64) *SubscribeBuilder
Offset set Offset of the event to start
func (*SubscribeBuilder) Topic ¶
func (s *SubscribeBuilder) Topic(topic string) *SubscribeBuilder
Topic set topic that will be subscribe