Documentation
¶
Overview ¶
Package pubsub implements publish subscriber patterns for usage in Golang
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetClient ¶
func SetClient(cli *Client)
SetClient sets the global pubsub client, useful in tests
func Subscribe ¶
func Subscribe(s Subscriber)
Subscribe starts a run loop with a Subscriber that listens to topics and waits for a syscall.SIGINT or syscall.SIGTERM
Types ¶
type Client ¶
type Client struct {
ServiceName string
Provider Provider
Middleware []Middleware
}
Client holds a reference to a Provider
func (Client) On ¶
func (c Client) On(opts HandlerOptions)
On takes HandlerOptions and subscribes to a topic, waiting for a protobuf message calling the function when a message is received
type Handler ¶
type Handler interface{}
Handler is a specific callback used for Subscribe in the format of.. func(ctx context.Context, obj proto.Message, msg *Msg) error for example, you can unmarshal a custom type.. func(ctx context.Context, accounts accounts.Account, msg *Msg) error you can also unmarshal a JSON object by supplying any type of interface{} func(ctx context.Context, accounts models.SomeJSONAccount, msg *Msg) error
type HandlerOptions ¶
type HandlerOptions struct {
// The topic to subscribe to
Topic string
// The name of this subscriber/function
Name string
// The name of this subscriber/function's service
ServiceName string
// The function to invoke
Handler Handler
// A message deadline/timeout
Deadline time.Duration
// Concurrency sets the maximum number of msgs to be run concurrently
// default: 20
Concurrency int
// Auto Ack the message automatically if return err == nil
AutoAck bool
// Decode JSON objects from pubsub instead of protobuf
JSON bool
}
HandlerOptions defines the options for a subscriber handler
type Middleware ¶
type Middleware interface {
SubscribeInterceptor(opts HandlerOptions, next MsgHandler) MsgHandler
PublisherMsgInterceptor(serviceName string, next PublishHandler) PublishHandler
}
Middleware is an interface to provide subscriber and publisher interceptors
type MsgHandler ¶
MsgHandler is the internal or raw message handler
type NoopProvider ¶
type NoopProvider struct{}
NoopProvider is a simple provider that does nothing, for testing, defaults
func (NoopProvider) Subscribe ¶
func (np NoopProvider) Subscribe(opts HandlerOptions, h MsgHandler)
Subscribe does nothing
type Provider ¶
type Provider interface {
Publish(ctx context.Context, topic string, m *Msg) error
Subscribe(opts HandlerOptions, handler MsgHandler)
Shutdown()
}
Provider is generic interface for a pub sub provider
type PublishHandler ¶
PublishHandler wraps a call to publish, for interception
type PublishResult ¶
type PublishResult struct {
Ready chan struct{}
Err error
}
A PublishResult holds the result from a call to Publish.
func Publish ¶
Publish is a convenience message which publishes to the current (global) publisher as protobuf
func PublishJSON ¶
func PublishJSON(ctx context.Context, topic string, obj interface{}) *PublishResult
PublishJSON is a convenience message which publishes to the current (global) publisher as JSON
type Subscriber ¶
type Subscriber interface {
// Setup is a required method that allows the subscriber service to add handlers
// and perform any setup if required, this is usually called by pubsub upon start
Setup(*Client)
}
Subscriber is a service that listens to events and registers handlers for those events
Directories
¶
| Path | Synopsis |
|---|---|
|
THIS IS AN EXPERIMENTAL DRIVER, PLEASE USE WITH CAUTION
|
THIS IS AN EXPERIMENTAL DRIVER, PLEASE USE WITH CAUTION |
|
middleware
|
|
|
Package test is a generated protocol buffer package.
|
Package test is a generated protocol buffer package. |