nats

package
v1.13.1 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: GPL-3.0 Imports: 3 Imported by: 6

Documentation

Overview

Package nats provides tools for comfort work during event processing with NATS broker.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommonConsumer added in v1.11.0

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

CommonConsumer is a base consumer for processing NATS messages.

func NewConsumer added in v1.11.0

func NewConsumer(
	url string,
	subject string,
	opts ...ConsumerOption,
) (*CommonConsumer, error)

NewConsumer creates *CommonConsumer with provided options.

func (*CommonConsumer) Run added in v1.11.0

func (c *CommonConsumer) Run() error

Run starts goroutines for NATS messages processing.

func (*CommonConsumer) Stop added in v1.11.0

func (c *CommonConsumer) Stop() error

Stop stops launched goroutines, which processes NATS messages.

type CommonPublisher

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

CommonPublisher is a base NATS publisher.

func NewPublisher added in v1.3.2

func NewPublisher(url string, opts ...natsbroker.Option) (*CommonPublisher, error)

NewPublisher creates *CommonPublisher.

func (*CommonPublisher) Close

func (p *CommonPublisher) Close() error

Close closes NATS connection.

func (*CommonPublisher) Publish

func (p *CommonPublisher) Publish(topic string, data []byte) error

Publish sends message to provided topic (subject).

type Consumer added in v1.11.0

type Consumer interface {
	Run() error
	Stop() error
}

Consumer asynchronously processes NATS messages in goroutines.

type ConsumerAlreadyRunningError added in v1.11.0

type ConsumerAlreadyRunningError struct {
	Message string
	BaseErr error
}

ConsumerAlreadyRunningError is an error, which represents, that consumer was already started and can not be started again.

func (ConsumerAlreadyRunningError) Error added in v1.11.0

func (ConsumerAlreadyRunningError) Unwrap added in v1.11.0

type ConsumerAlreadyStoppedError added in v1.11.0

type ConsumerAlreadyStoppedError struct {
	Message string
	BaseErr error
}

ConsumerAlreadyStoppedError is an error, which represents, that consumer was not started yet or was already stopped.

func (ConsumerAlreadyStoppedError) Error added in v1.11.0

func (ConsumerAlreadyStoppedError) Unwrap added in v1.11.0

type ConsumerOption added in v1.11.0

type ConsumerOption func(options *consumerOptions) error

ConsumerOption represents golang functional option pattern func for Consumer configuration.

func WithCloseHandler

func WithCloseHandler(handler func(connection *natsbroker.Conn)) ConsumerOption

WithCloseHandler sets handler for connection with NATS closure.

func WithDisconnectErrorHandler

func WithDisconnectErrorHandler(handler func(connection *natsbroker.Conn, err error)) ConsumerOption

WithDisconnectErrorHandler sets handler for disconnection from server.

func WithErrorHandler

func WithErrorHandler(
	handler func(connection *natsbroker.Conn, subscription *natsbroker.Subscription, err error),
) ConsumerOption

WithErrorHandler sets handler for processing error during message processing.

func WithGoroutinesPoolSize

func WithGoroutinesPoolSize(size int) ConsumerOption

WithGoroutinesPoolSize sets number of goroutines for process messages from NATS via message channel.

func WithMessageChannelBufferSize

func WithMessageChannelBufferSize(size int) ConsumerOption

WithMessageChannelBufferSize sets buffer for channel, where NATS will store messages for processing.

func WithMessageHandler

func WithMessageHandler(handler func(message *natsbroker.Msg)) ConsumerOption

WithMessageHandler sets handler for received message.

func WithNatsOptions

func WithNatsOptions(opts ...natsbroker.Option) ConsumerOption

WithNatsOptions sets NATS option for connection with broker configuration.

type Publisher

type Publisher interface {
	Publish(subject string, content []byte) error
	Close() error
}

Publisher publishes messages to NATS broker.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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