eventpublisher

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

README

Build Status

eventstream-go-sdk

Go SDK for integrating with AccelByte's event stream

Supported stream

Currently these stream are supported by this library:

Kafka stream

This will publish an event in to Kafka stream. Each event type will be published into different topic by using the topic field inside the event. For example, if event has event.topic=update_user, it will be pushed to update_user Kafka topic.

To create a client for publishing to Kafka stream, use this function:

client, err := NewKafkaClient("realm-name", []string{"localhost:9092"})
stdout stream

This stream is for testing purpose. This will print the event in stdout. It should not be used in production since this will print unnecessary log.

To create a client for stdout, use this function:

client := NewStdoutClient("realm-name")
blackhole

This is used when we don't want the service to send event data to anywhere.

To create a client for stdout, use this function:

client := NewBlackholeClient()

Usage

Importing
eventpublisher "github.com/AccelByte/eventstream-go-sdk"
Creating an event

Although the Event is exposed, it's strongly recommended to not creating them by yourself. For that, we can use the NewEvent() function to make sure all required fields are not empty.

To add additional fields, we can use WithFields() function.

It's strongly recommended to create your own event constructor to wrap the NewEvent() and WithFields() to force additional fields to be uniform. The example can be read in /example folder.

Publishing an event

There are two type of event publishing in this library.

Synchronous

This type will publish an event in synchronous manner. The publish function will not return anything until the process is done. The function will also return the status of the publishing.

err := client.PublishEvent(event)
Asynchronous

This type will publish an event in asynchronous manner. The publish function will instantaneously return without having to wait the process. We can't catch the status of this publishing. However, if error occur, it will be logged.

client.PublishEventAsync(event)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlackholeClient

type BlackholeClient struct{}

BlackholeClient satisfies the publisher for mocking

func NewBlackholeClient

func NewBlackholeClient() *BlackholeClient

NewBlackholeClient creates new telemetry client

func (*BlackholeClient) PublishEvent

func (client *BlackholeClient) PublishEvent(event *Event) error

func (*BlackholeClient) PublishEventAsync

func (client *BlackholeClient) PublishEventAsync(event *Event)

type Event

type Event struct {
	Time             time.Time              `json:"time"`
	EventID          int                    `json:"event_id"`
	EventType        int                    `json:"event_type"`
	EventLevel       int                    `json:"event_level"`
	Service          string                 `json:"service"`
	ClientIDs        []string               `json:"client_ids"`
	UserID           string                 `json:"user_id"`
	TargetUserIDs    []string               `json:"target_user_ids"`
	Namespace        string                 `json:"namespace"`
	TargetNamespace  string                 `json:"target_namespace"`
	TraceID          string                 `json:"trace_id"`
	SessionID        string                 `json:"session_id"`
	Privacy          bool                   `json:"privacy"`
	Realm            string                 `json:"realm"`
	Topic            string                 `json:"topic"`
	AdditionalFields map[string]interface{} `json:"additional_fields,omitempty"`
}

Event holds the outer telemetry Event structure

func NewEvent

func NewEvent(eventID int,
	eventType int,
	eventLevel int,
	service string,
	clientIDs []string,
	userID string,
	targetUserIDs []string,
	namespace string,
	targetNamespace string,
	traceID string,
	sessionID string,
	privacy bool,
	topic string) *Event

NewEvent creates new Event without additional fields

func (*Event) WithFields

func (event *Event) WithFields(fields map[string]interface{}) *Event

WithFields add additional fields

type KafkaClient

type KafkaClient struct {
	// contains filtered or unexported fields
}

KafkaClient satisfies the publisher to Kafka

func NewKafkaClient

func NewKafkaClient(realm string, brokerList []string, producerConfiguration ...*KafkaConfig) (*KafkaClient, error)

NewKafkaClient creates new client to publish event to kafka The first producerConfiguration is the asynchronous producer configuration meanwhile the second is the synchronous one

func (*KafkaClient) PublishEvent

func (client *KafkaClient) PublishEvent(event *Event) error

PublishEvent push an event to a Kafka topic synchronously

func (*KafkaClient) PublishEventAsync

func (client *KafkaClient) PublishEventAsync(event *Event)

PublishEventAsync publish to a Kafka topic asynchronously

type KafkaConfig

type KafkaConfig struct {
	DialTimeout          time.Duration
	ReadTimeout          time.Duration
	WriteTimeout         time.Duration
	MetadataRetryMax     int
	MetadataRetryBackoff time.Duration
}

KafkaConfig is Kafka configuration to wait for a successful metadata response

type PublisherClient

type PublisherClient interface {
	PublishEvent(event *Event) error
	PublishEventAsync(event *Event)
}

PublisherClient provides interface for publish the Event to stream

type StdoutClient

type StdoutClient struct {
	// contains filtered or unexported fields
}

StdoutClient satisfies the publisher for mocking

func NewStdoutClient

func NewStdoutClient(realm string) *StdoutClient

NewStdoutClient creates new telemetry client

func (*StdoutClient) PublishEvent

func (client *StdoutClient) PublishEvent(event *Event) error

func (*StdoutClient) PublishEventAsync

func (client *StdoutClient) PublishEventAsync(event *Event)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL