Documentation ¶
Overview ¶
Package pubsub provides the development kit for working with Publish / Subscribe mechanism between the gateway and scheduler services.
This feature is used by the gateway as a publisher and by the scheduler as a subscriber. This way, the gateway can publish jobs in realtime to the scheduler that then will take care of forwarding them to the appropriate actions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var AvailableAdapters = map[string]bool{ "aws": true, "azure": true, "google": true, "kafka": true, "nats": true, "rabbitmq": true, }
AvailableAdapters is a list of available pubsub adapters.
var Defaults = &Options{ Context: context.Background(), Topic: "blacksmith", Broker: "blacksmith", Subscription: "blacksmith", }
Defaults are the defaults options set for the pubsub. When not set, these values will automatically be applied.
var InterfacePubSub = "pubsub"
InterfacePubSub is the string representation for the pubsub interface.
Functions ¶
This section is empty.
Types ¶
type Message ¶ added in v0.12.0
type Message struct { // Body is the marshaled content of the message. Body []byte `json:"body"` // Meta can hold some metadata about the message. Meta map[string]string `json:"meta"` }
Message holds the information of a message received by the subscriber for the source triggers.
type Options ¶
type Options struct { // From is used to set the desired pubsub adapter. It must be one of // AvailableAdapters. From string `json:"from,omitempty"` // Context is a free key-value dictionary that will be passed to the underlying // adapter. Context context.Context `json:"-"` // Connection is the connection string to connect to the pubsub. Connection string `json:"-"` // Topic is the topic name the pubsub adapter will use to publish messages to. // // Example for Kafka: "<topic>" // Example for NATS: "<subject>" // Example for RabbitMQ: "<exchange>" // Example for Amazon Web Services: "arn:aws:sns:<region>:<id>:<topic>" // Example for Google Cloud: "projects/<project>/topics/<topic>" // Example for Microsoft Azure: "<topic>" Topic string `json:"topic"` // Broker is the middleman's name to use for pushing or subscribing to messages. // It is not applicable for every adapters. It can be used to group messages per // queue and therefore help the adapter create a load balancing or ensure a // single active consumer. // // Example for Kafka: "<consumer-group>" // Example for NATS: "<queue>" // Example for RabbitMQ: N/A // Example for Amazon Web Services: N/A // Example for Google Cloud: N/A // Example for Microsoft Azure: N/A Broker string `json:"broker,omitempty"` // Subscription is the subscription name the pubsub adapter will use to subscribe // to messages when different from the topic. // // Example for Kafka: N/A // Example for NATS: N/A // Example for RabbitMQ: "<queue>" // Example for Amazon Web Services: "arn:aws:sqs:<region>:<id>:<queue>" // Example for Google Cloud: "projects/<project>/subscriptions/<subscription>" // Example for Microsoft Azure: "<subscription>" Subscription string `json:"subscription,omitempty"` }
Options is the options a user can pass to use the pubsub adapter.
type PubSub ¶
type PubSub interface { // String returns the string representation of the adapter. // // Example: "nats" String() string // Options returns the options originally passed to the Options struct. This // can be used to validate and override user's options if necessary. Options() *Options // Publisher returns the interface in charge of publishing messages in realtime. // Can be nil if PubSub is disabled. Publisher() Publisher // Subscriber returns the interface in charge of subscribing to messages in // realtime. Can be nil if PubSub is disabled. Subscriber() Subscriber }
PubSub is the interface used to load events' jobs to destinations in realtime. When disabled, the gateway and scheduler will work as expected but will load jobs to destinations given the configured schedule.
type Publisher ¶
type Publisher interface { // Init let you initialize the Publisher. Init(*Toolkit) error // Send publishes a queue. It only returns after the queue has been sent, or // failed to be sent. Send(*Toolkit, *store.Queue) error // Shutdown flushes pending message sends and disconnects the Publisher. It only // return after all pending messages have been sent. Shutdown(*Toolkit) error }
Publisher is in charge of creating topics and sending messages to the Subscriber.
type Subscriber ¶
type Subscriber interface { // Init let you initialize the Subscriber. Init(*Toolkit) error // Receive receives and returns the next queue from the Subscriber, blocking and // polling if none are available. Receive(*Toolkit) (*store.Queue, error) // Shutdown flushes pending ack sends and disconnects the Subscriber. Shutdown(*Toolkit) error }
Subscriber is in charge of receiving messages on given topics.