nats

package
v1.0.26 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

The nats package provides a NATS implementation of the pubsub interface.

Index

Constants

View Source
const Name = "nats"

Name is the name of the pubsub.

Variables

This section is empty.

Functions

func Get

func Get() pubsub.IPubSub

Get returns a setup NATS, or set it up.

func New

func New(ctx context.Context, url string, options ...Option) (pubsub.IPubSub, error)

New creates a new NATS pubsub.

func Set

func Set(ps pubsub.IPubSub)

Set sets the singleton. Useful for testing.

Types

type NATS

type NATS struct {
	*pubsub.PubSub

	// Options are the NATS configuration.
	Options []Option `json:"-" validate:"required"`

	// Client is the NATS client.
	Client *natsgo.Conn

	// URL is the NATS URL.
	URL string `json:"url" validate:"required"`
}

NATS pubsub definition.

func (*NATS) Close

func (n *NATS) Close() error

Close the connection to the Pub Sub broker.

func (*NATS) GetClient

func (n *NATS) GetClient() any

GetClient returns the storage client. Use that to interact with the underlying storage client.

func (*NATS) MustPublish added in v1.0.14

func (n *NATS) MustPublish(ctx context.Context, msgs ...*message.Message) []*message.Message

MustPublish sends a message to a topic. In case of error it will panic.

func (*NATS) MustPublishAsync added in v1.0.14

func (n *NATS) MustPublishAsync(ctx context.Context, messages ...*message.Message)

MustPublishAsync sends a message to a topic asynchronously. In case of error it will panic.

func (*NATS) MustSubscribe added in v1.0.14

func (n *NATS) MustSubscribe(ctx context.Context, subscriptions ...*subscription.Subscription) []*subscription.Subscription

MustSubscribe to a topic. In case of error it will panic.

func (*NATS) MustSubscribeAsync added in v1.0.21

func (n *NATS) MustSubscribeAsync(ctx context.Context, subscriptions ...*subscription.Subscription)

MustSubscribeAsync to a topic asynchronously. In case of error it will panic.

func (*NATS) Publish

func (n *NATS) Publish(
	ctx context.Context,
	messages []*message.Message,
	opts ...pubsub.Func,
) ([]*message.Message, concurrentloop.Errors)

Publish sends a message to a topic.

func (*NATS) Subscribe

func (n *NATS) Subscribe(
	ctx context.Context,
	subscriptions []*subscription.Subscription,
	opts ...pubsub.Func,
) ([]*subscription.Subscription, concurrentloop.Errors)

Subscribe to a topic.

func (*NATS) Unsubscribe

func (n *NATS) Unsubscribe(ctx context.Context, subscriptions ...*subscription.Subscription) error

Unsubscribe from a topic.

type Option added in v1.0.5

type Option = natsgo.Option

Option is for the NATS configuration.

Jump to

Keyboard shortcuts

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