Documentation ¶
Index ¶
Constants ¶
const ( // NATS connects to an external NATS cluster to provide event subscribing and publishing across // multiple Response instances each connected to the same NATS cluster. This is the preferred // production system. NATS = "nats" )
Variables ¶
This section is empty.
Functions ¶
func NewMessage ¶
NewMessage creates a new Message containing the event and body. This message can be sent using the Publish method.
Types ¶
type Driver ¶
type Driver string
Driver is a type of Driver available to use as a backing pubsub implementation.
const ( // Embedded is an embedded pubsub driver that provides in-memory event subscribing and publishing // and is acceptable for testing and development purposes. In general you should use a more robust // pubsub implementation in production. Embedded Driver = "embedded" )
type Listener ¶
Listener is a single subscribed listener for an event.
func (*Listener) Channel ¶
Channel returns the channel that emits pubsub.Message's whenever they are received. Channel will also
func (*Listener) Unsubscribe ¶
func (l *Listener) Unsubscribe()
Unsubscribe unsubscribes the listener. The listener will no longer receive messages from the subscribed event.
type Options ¶
type Options struct { Logger log.ComponentLogger Driver Driver Weight int64 Subject string URL string }
Options configures all of the options for the PubSub implementation.
type PubSub ¶
type PubSub interface { Publisher Subscriber // Shutdown should be called once before the program exits to close all existing connections // and finish processing any events already in-flight. Close(ctx context.Context) }
PubSub is a Publisher/Subscriber implementation.
type Publisher ¶
type Publisher interface { // Publish publishes events to the Response cluster using the configured pubsub implementation. Publish(ctx context.Context, messages ...*pubsub.Message) error }
Publisher is implemented by pubsub implementations that can publish events.
type Subscriber ¶
type Subscriber interface { // On subscribes to an event until the listener is unsubscibed either internally or by calling Subscriber.Unsubscribe() // with the Listener or calling Listener.Unsubscribe() directly. On(ctx context.Context, event Event, buffer int) *Listener // Once works similarly to On, however nlike On, when Once receives its first event the listener will be closed automatically. Once(ctx context.Context, event Event) *Listener // Unsubscribe unsubscribes the given Listener by calling the Listener.Unsubscribe() method. Unsubscribe(lis *Listener) }
Subscriber is implemented by pubsub implementations and supports subscribing to events.