pubsub

package
v0.1.9-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PROJECTID_HEADER_KEY  = "pubsub_project_id"
	TOPIC_ID_HEADER_KEY   = "pubsub_topic_id"
	EVENT_TYPE_HEADER_KEY = "pubsub_event_type"
	DEFAULT_TOPIC_ID      = "gameserver.events"
)

Variables

This section is empty.

Functions

func CheckEmpty

func CheckEmpty(source, newValue string) string

CheckEmpty is a helper function that will check if source is empty and assign newValue if so

func GetTopicIDFromHeader

func GetTopicIDFromHeader(envelope *events.Envelope) (string, bool)

GetTopicIDFromHeader extracts the topicID from the envelope's header

Types

type Config

type Config struct {
	ProjectID       string
	GenericTopicID  string
	OnAddTopicID    string
	OnUpdateTopicID string
	OnDeleteTopicID string
}

Config is the data structure that holds the configuration passed to the Google Pub/Sub Broker. GenericTopicID is used when specific events topics are not present and all the events should be published to a single topic. Defaults to "gameserver.events"

func (*Config) ApplyDefaults

func (c *Config) ApplyDefaults()

ApplyDefaults sets default values for the Config used by the PubSubBroker

type PubSubBroker

type PubSubBroker struct {
	*Config
	*pubsub.Client
}

PubSubBroker is a implementation of the Broker interface that uses Google Cloud PubSub for publishing messages

func NewPubSubBroker

func NewPubSubBroker(config *Config, opts ...option.ClientOption) (*PubSubBroker, error)

func (*PubSubBroker) BuildEnvelope

func (b *PubSubBroker) BuildEnvelope(event events.Event) (*events.Envelope, error)

BuildEnvelope builds the envelope for a particular event. It will set the enveloper header and message content

func (*PubSubBroker) SendMessage

func (b *PubSubBroker) SendMessage(envelope *events.Envelope) error

SendMessage publishes a particular envelope to a Google Pub/Sub topic.

func (*PubSubBroker) SetEnvelopeHeader

func (b *PubSubBroker) SetEnvelopeHeader(event events.Event, envelope *events.Envelope)

SetEnvelopeHeader sets the envelope header for a particular event. Those specific headers will be used by the broker when publishing the message to the Google Pub/Sub topic

func (*PubSubBroker) TopicFor

func (b *PubSubBroker) TopicFor(ctx context.Context, topicID string) (*pubsub.Topic, error)

TopicFor returns a topic if it already exists on Google Pub/Sub

Jump to

Keyboard shortcuts

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