nats

package
v0.0.0-...-2cf2c7d Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package nats provides an implementation for the flow pub/sub interface which uses NATS.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	*nats.Conn
}

Conn represents a connection to a NATS server.

func Connect

func Connect(addr string, opts ...Option) (Conn, error)

Connect connects to the NATS servers with the given addresses. Address formats follow the NATS convention. For multiple addresses addr should contain a comma separated list.

func (Conn) Close

func (c Conn) Close() error

Close closes the connection.

func (Conn) Publish

func (c Conn) Publish(ctx context.Context, stream string, data []byte) error

Publish publishes data to the specified stream.

func (Conn) Subscribe

func (c Conn) Subscribe(ctx context.Context, stream, group string, h flow.PubSubHandler) (flow.Subscription, error)

Subscribe installs a handler for the specified stream. The handler shares the incoming message stream with other handlers of the same group. If the group is empty, a separate stream will be assigned to the handler.

type Option

type Option func(*nats.Options) error

Option represents an option to configure NATS connections.

func ClientName

func ClientName(name string) Option

ClientName defines a name for the connected client.

func Credentials

func Credentials(cred string) Option

Credentials sets the credentials which should be used for a server connection. If the given credentials are of the form "user:password", an user/password pair will be configured. Otherwise a security token is set. This option can be used twice, for the user/password pair and for the token.

func Reconnects

func Reconnects(count int, interval time.Duration) Option

Reconnects enables or disables reconnections to the NATS servers. The count parameter specifies the maximum number of reconnect attempts, while the interval specifies the wait time between those attempts. If count is zero, reconnections will be disabled. Otherwise, the reconnections will be enabled.

func TLS

func TLS(conf *tls.Config) Option

TLS enables secure connections to the NATS servers.

func TLSFromFiles

func TLSFromFiles(certFile, keyFile string) Option

TLSFromFiles enables secure connections to the NATS servers by loading a key pair from the given files.

Jump to

Keyboard shortcuts

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