pubsub

package
v0.0.0-...-8d1786a Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2020 License: Apache-2.0 Imports: 8 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPubSubClient

func NewPubSubClient(projectID string) (*pubsub.Client, *context.Context, error)

NewPubSubClient creates a new pubsub client via Google project ID

Types

type EventHandler

type EventHandler interface {
	// Handle runs the logic to handle the event as appropriate for the event
	// Returns a bool whether the event was handled and an error if occurred
	Handle(event []byte) (bool, error)
	// Name returns a readable name for this particular event handler
	Name() string
}

EventHandler is an interface to a governance event handler.

type GooglePubSub

type GooglePubSub struct {
	SubscribeChan    chan *pubsub.Message
	SubscribeErrChan chan error
	// contains filtered or unexported fields
}

GooglePubSub is a wrapper around handling for Google Pub/Sub. Manages pooled goroutines of publishers and subscribers.

func NewGooglePubSub

func NewGooglePubSub(projectID string) (*GooglePubSub, error)

NewGooglePubSub returns a new GooglePubSub struct

func (*GooglePubSub) CreateSubscription

func (g *GooglePubSub) CreateSubscription(topicName string, subName string) error

CreateSubscription creates a new subscription with a default config

func (*GooglePubSub) CreateSubscriptionWithConfig

func (g *GooglePubSub) CreateSubscriptionWithConfig(topicName string, subName string, config pubsub.SubscriptionConfig) error

CreateSubscriptionWithConfig creates a new subscription

func (*GooglePubSub) CreateTopic

func (g *GooglePubSub) CreateTopic(topicName string) error

CreateTopic creates a new pubsub topic

func (*GooglePubSub) DeleteSubscription

func (g *GooglePubSub) DeleteSubscription(subName string) error

DeleteSubscription deletes an existing subscription

func (*GooglePubSub) DeleteTopic

func (g *GooglePubSub) DeleteTopic(topicName string) error

DeleteTopic deletes an existing pubsub topic

func (*GooglePubSub) NumPublishersRunning

func (g *GooglePubSub) NumPublishersRunning() int

NumPublishersRunning return the number of publishers goroutines running.

func (*GooglePubSub) NumSubscribersRunning

func (g *GooglePubSub) NumSubscribersRunning() int

NumSubscribersRunning return the number of subscriber goroutines running.

func (*GooglePubSub) Publish

func (g *GooglePubSub) Publish(msg *GooglePubSubMsg) error

Publish publishes the given message to the pubsub.

func (*GooglePubSub) PublishersStarted

func (g *GooglePubSub) PublishersStarted() bool

PublishersStarted returns true if the publishers are running, false if not.

func (*GooglePubSub) StartPublishers

func (g *GooglePubSub) StartPublishers() error

StartPublishers starts up a pool of PubSub publishers.

func (*GooglePubSub) StartSubscribers

func (g *GooglePubSub) StartSubscribers(subscriptionName string) error

StartSubscribers starts up a pool of PubSub publishers using a default config

func (*GooglePubSub) StartSubscribersWithConfig

func (g *GooglePubSub) StartSubscribersWithConfig(config SubscribeConfig) error

StartSubscribersWithConfig starts up a pool of PubSub publishers.

func (*GooglePubSub) StopPublishers

func (g *GooglePubSub) StopPublishers() error

StopPublishers will stop the publisher goroutines

func (*GooglePubSub) StopSubscribers

func (g *GooglePubSub) StopSubscribers() error

StopSubscribers will stop the subscriber goroutines

func (*GooglePubSub) SubscribersStarted

func (g *GooglePubSub) SubscribersStarted() bool

SubscribersStarted returns true if the subscribers are running, false if not.

func (*GooglePubSub) SubscriptionExists

func (g *GooglePubSub) SubscriptionExists(subName string) (bool, error)

SubscriptionExists checks for existence of an existing subscription

func (*GooglePubSub) SubscriptionName

func (g *GooglePubSub) SubscriptionName() string

SubscriptionName returns the name of the subscription to track.

func (*GooglePubSub) TopicExists

func (g *GooglePubSub) TopicExists(topicName string) (bool, error)

TopicExists checks the existence of a topic

type GooglePubSubMsg

type GooglePubSubMsg struct {
	Topic   string
	Payload string
}

GooglePubSubMsg represents a messages to be published

type SubscribeConfig

type SubscribeConfig struct {
	Name    string
	AutoAck bool
}

SubscribeConfig is a config for the wrapper around a Google Pubsub Subscription

type Workers

type Workers struct {
	Errors chan error
	// contains filtered or unexported fields
}

Workers controls the events workers that handles incoming pubsub events. One instance of Workers normally points to one particular queue of events by event types. i.e. one Workers instance for gov events and a separate instance for token events. Meant to be generic framework where the pubsub queue and the set of event handlers are configured before use.

func NewWorkers

func NewWorkers(config *WorkersConfig) (*Workers, error)

NewWorkers configures and returns a new Workers struct

func (*Workers) NumActiveWorkers

func (w *Workers) NumActiveWorkers() int

NumActiveWorkers returns the number of active workers

func (*Workers) Start

func (w *Workers) Start()

Start starts up the governance event pubsub workers. This is a blocking call.

type WorkersConfig

type WorkersConfig struct {
	PubSubProjectID        string
	PubSubTopicName        string
	PubSubSubscriptionName string
	NumWorkers             int
	QuitChan               chan struct{}
	EventHandlers          []EventHandler
}

WorkersConfig configures the governance event pubsub workers

Jump to

Keyboard shortcuts

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