nats_provider

package
v0.0.0-...-4dd3280 Latest Latest
Warning

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

Go to latest
Published: May 12, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAlreadySubscribed is an error firing when caller tries to subscribe to the same subject they are already subscribed
	ErrAlreadySubscribed = errors.New("only one subscription per subject supported")
)

Functions

This section is empty.

Types

type NATSProvider

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

NATSProvider is a struct representing NATS communications.

func New

func New(connectionURLs []string) *NATSProvider

New is the constructor for NATSProvider. connectionURLs - addresses of NATS cluster. logger - logger to log error events into.

func (*NATSProvider) Close

func (p *NATSProvider) Close()

Close closes the connection with NATS server/cluster.

func (*NATSProvider) Flush

func (p *NATSProvider) Flush() error

func (*NATSProvider) Open

func (p *NATSProvider) Open() (err error)

Open connects to NATS cluster by addresses provided in constructor.

func (*NATSProvider) Publish

func (p *NATSProvider) Publish(subject string, msg []byte) error

Publish publishes a message with contents in msg into the provided subject.

func (*NATSProvider) Request

func (p *NATSProvider) Request(subject string, msg []byte) (*nats.Msg, error)

func (*NATSProvider) Subscribe

func (p *NATSProvider) Subscribe(subject string, callback func(*nats.Msg)) error

Subscribe creates a subscription to specified subject with the provided callback. Only one subscruption per subject supported, to change the subscription unsubscribe first. Attempting to subscribe for the same subject will return ErrAlreadySubscribed, the subscription stays unchanged.

func (*NATSProvider) Unsubscribe

func (p *NATSProvider) Unsubscribe(subject string) error

Unsubscribe unsubscribes from the provided subject. If no subscription exists for the subject, it's a no-op.

Jump to

Keyboard shortcuts

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