nats

package
v1.1.0-beta.17 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: MIT Imports: 5 Imported by: 3

Documentation

Index

Constants

View Source
const (
	PluginsRoot = root + ".plugins"
)

Variables

This section is empty.

Functions

func ConfigAdd

func ConfigAdd(path string)

func NewConn

func NewConn(ctx context.Context, plugins ...Plugin) (*nats.Conn, error)

NewConn returns a new connection with default options.

func NewConnWithConfigPath

func NewConnWithConfigPath(ctx context.Context, path string) (*nats.Conn, error)

NewConnWithConfigPath returns a new nats connection with options from config path.

func NewConnWithOptions

func NewConnWithOptions(ctx context.Context, options *Options, plugins ...Plugin) (*nats.Conn, error)

Register registers a nats connection.

Types

type Options

type Options struct {
	Url           string
	MaxReconnects int
	ReconnectWait time.Duration
}

Options nats connection options.

func NewOptions

func NewOptions() (*Options, error)

NewOptions returns options from config file or environment vars.

func NewOptionsWithPath

func NewOptionsWithPath(path string) (opts *Options, err error)

NewOptionsWithPath unmarshals options based a given key path.

type Plugin

type Plugin func(context.Context, *nats.Conn) error

Plugin defines a function to process plugin.

type Publisher

type Publisher struct {
	// contains filtered or unexported fields
}

Publisher represents a nats publisher.

func NewPublisher

func NewPublisher(ctx context.Context, middlewares ...PublisherMiddleware) (*Publisher, error)

NewPublisher returns a new nats publisher with default options.

func NewPublisherWithConfigPath

func NewPublisherWithConfigPath(ctx context.Context, path string, middlewares ...PublisherMiddleware) (*Publisher, error)

NewPublisherWithConfigPath returns a new nats publisher with options from config path.

func NewPublisherWithOptions

func NewPublisherWithOptions(ctx context.Context, options *Options, middlewares ...PublisherMiddleware) (*Publisher, error)

NewPublisherWithOptions returns a new nats publisher with options.

func (*Publisher) Conn

func (p *Publisher) Conn() *nats.Conn

Conn returns this publisher connection.

func (*Publisher) Publish

func (p *Publisher) Publish(ctx context.Context, msg *nats.Msg) error

Publish publishes the message to nats.

type PublisherMiddleware

type PublisherMiddleware interface {
	Before(context.Context, *nats.Conn, *nats.Msg) (context.Context, error)
	After(context.Context) error
}

PublisherMiddleware defines an interface for a nats publisher plugin.

type Subscriber

type Subscriber struct {
	// contains filtered or unexported fields
}

Subscriber represents a nats subscriber.

func NewSubscriber

func NewSubscriber(ctx context.Context, msgHandlers ...msgHandler) (*Subscriber, error)

NewSubscriber returns a new nats subscriber with default options.

func NewSubscriberWithConfigPath

func NewSubscriberWithConfigPath(ctx context.Context, path string, msgHandlers ...msgHandler) (*Subscriber, error)

NewSubscriberWithConfigPath returns a new nats subscriber with options from config path.

func NewSubscriberWithOptions

func NewSubscriberWithOptions(ctx context.Context, options *Options, msgHandlers ...msgHandler) (*Subscriber, error)

NewSubscriberWithOptions returns a new nats subscriber with options.

func (*Subscriber) Conn

func (p *Subscriber) Conn() *nats.Conn

func (*Subscriber) Subscribe

func (p *Subscriber) Subscribe(subj string, queue string, cb nats.MsgHandler) (*nats.Subscription, error)

Subscribe subscribes a handler to nats queue subject.

Directories

Path Synopsis
plugins

Jump to

Keyboard shortcuts

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