pubsub

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: May 25, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package pubsub provides the development kit for working with Publish / Subscribe systems.

This feature shall be used by the gateway as a publisher and by the scheduler as a subscriber. This way, the gateway can publish events in realtime to the scheduler that then will take care of forwarding the events' jobs to the desired destinations.

A pubsub adapter can be generated using the Blacksmith CLI:

$ blacksmith generate pubsub

Note: Adapter generation using the Blacksmith CLI is a feature only available in Blacksmith Enterprise.

Index

Constants

This section is empty.

Variables

View Source
var AvailableAdapters = map[string]bool{
	"kafka":    true,
	"nats":     true,
	"rabbitmq": true,
}

AvailableAdapters is a list of available pubsub adapters.

View Source
var Defaults = &Options{
	Enabled: false,
	Topic:   "blacksmith",
}

Defaults are the defaults options set for the pubsub. When not set, these values will automatically be applied.

View Source
var InterfacePubSub = "pubsub"

InterfacePubSub is the string representation for the pubsub interface.

Functions

This section is empty.

Types

type Options

type Options struct {

	// From can be used to download, install, and use an existing adapter. This way
	// the user does not need to develop a custom pubsub adapter.
	From string

	// Load can be used to load and use a custom pubsub adapter developed in-house.
	Load PubSub

	// Context is a free key-value dictionary that will be passed to the underlying
	// adapter.
	Context context.Context

	// Enabled allows the user to enable the PubSub interface and this way distribute
	// jobs to destinations in realtime. If disabled, the scheduler will load jobs
	// to destinations given the schedule of each destination and event.
	Enabled bool

	// Connection is the connection string to connect to the pubsub.
	Connection string

	// Topic is the topic name the pubsub adapter will use to publish and subscribe
	// messages to.
	Topic string
}

Options is the options a user can pass to create a new pubsub.

func (*Options) ValidateAndLoad

func (opts *Options) ValidateAndLoad() (PubSub, error)

ValidateAndLoad validates the pubsub's options and returns a valid pubsub interface.

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.

type Toolkit

type Toolkit struct {

	// Logger gives access to the logrus Logger passed in options when creating the
	// Blacksmith application.
	Logger *logrus.Logger

	// Context is the context originally passed when creating the pubsub.
	Context context.Context
}

Toolkit gives you access to a set of usefull tools when dealing with Publisher and Subscriber.

Jump to

Keyboard shortcuts

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