nats

package
v1.2.12 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 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 CommonPublisher

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

CommonPublisher is a base NATS publisher.

func NewCommonPublisher

func NewCommonPublisher(url string, opts ...nats.Option) (*CommonPublisher, error)

NewCommonPublisher 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 CommonWorker

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

CommonWorker is a base worker for processing NATS messages.

func NewCommonWorker

func NewCommonWorker(
	url string,
	subject string,
	opts ...WorkerOption,
) (*CommonWorker, error)

NewCommonWorker creates *CommonWorker with provided options.

func (*CommonWorker) Run

func (w *CommonWorker) Run() error

Run starts goroutines for NATS messages processing.

func (*CommonWorker) Stop

func (w *CommonWorker) Stop() error

Stop stops launched goroutines, which processes NATS messages.

type Publisher

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

Publisher publishes messages to NATS broker.

type Worker

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

Worker asynchronously processing NATS messages in goroutines.

type WorkerAlreadyRunningError

type WorkerAlreadyRunningError struct {
	Message string
	BaseErr error
}

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

func (WorkerAlreadyRunningError) Error

func (WorkerAlreadyRunningError) Unwrap

func (e WorkerAlreadyRunningError) Unwrap() error

type WorkerAlreadyStoppedError

type WorkerAlreadyStoppedError struct {
	Message string
	BaseErr error
}

WorkerAlreadyStoppedError is an error, which represents, that worker was not started yet or was already stopped.

func (WorkerAlreadyStoppedError) Error

func (WorkerAlreadyStoppedError) Unwrap

func (e WorkerAlreadyStoppedError) Unwrap() error

type WorkerOption

type WorkerOption func(options *workerOptions) error

WorkerOption represents golang functional option pattern func for Worker configuration.

func WithCloseHandler

func WithCloseHandler(handler func(connection *nats.Conn)) WorkerOption

WithCloseHandler sets handler for connection with NATS closure.

func WithDisconnectErrorHandler

func WithDisconnectErrorHandler(handler func(connection *nats.Conn, err error)) WorkerOption

WithDisconnectErrorHandler sets handler for disconnection from server.

func WithErrorHandler

func WithErrorHandler(handler func(connection *nats.Conn, subscription *nats.Subscription, err error)) WorkerOption

WithErrorHandler sets handler for processing error during message processing.

func WithGoroutinesPoolSize

func WithGoroutinesPoolSize(size int) WorkerOption

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

func WithMessageChannelBufferSize

func WithMessageChannelBufferSize(size int) WorkerOption

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

func WithMessageHandler

func WithMessageHandler(handler func(message *nats.Msg)) WorkerOption

WithMessageHandler sets handler for received message.

func WithNatsOptions

func WithNatsOptions(opts ...nats.Option) WorkerOption

WithNatsOptions sets NATS option for connection with broker configuration.

Jump to

Keyboard shortcuts

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