Documentation
¶
Overview ¶
Package nats provides tools for comfort work during event processing with NATS broker.
Index ¶
- type CommonPublisher
- type CommonWorker
- type Publisher
- type Worker
- type WorkerAlreadyRunningError
- type WorkerAlreadyStoppedError
- type WorkerOption
- func WithCloseHandler(handler func(connection *natsbroker.Conn)) WorkerOption
- func WithDisconnectErrorHandler(handler func(connection *natsbroker.Conn, err error)) WorkerOption
- func WithErrorHandler(...) WorkerOption
- func WithGoroutinesPoolSize(size int) WorkerOption
- func WithMessageChannelBufferSize(size int) WorkerOption
- func WithMessageHandler(handler func(message *natsbroker.Msg)) WorkerOption
- func WithNatsOptions(opts ...natsbroker.Option) WorkerOption
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 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.
type CommonWorker ¶
type CommonWorker struct {
// contains filtered or unexported fields
}
CommonWorker is a base worker for processing NATS messages.
func NewWorker ¶ added in v1.3.2
func NewWorker( url string, subject string, opts ...WorkerOption, ) (*CommonWorker, error)
NewWorker 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 WorkerAlreadyRunningError ¶
WorkerAlreadyRunningError is an error, which represents, that worker was already started and can not be started again.
func (WorkerAlreadyRunningError) Error ¶
func (e WorkerAlreadyRunningError) Error() string
func (WorkerAlreadyRunningError) Unwrap ¶
func (e WorkerAlreadyRunningError) Unwrap() error
type WorkerAlreadyStoppedError ¶
WorkerAlreadyStoppedError is an error, which represents, that worker was not started yet or was already stopped.
func (WorkerAlreadyStoppedError) Error ¶
func (e WorkerAlreadyStoppedError) Error() string
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 *natsbroker.Conn)) WorkerOption
WithCloseHandler sets handler for connection with NATS closure.
func WithDisconnectErrorHandler ¶
func WithDisconnectErrorHandler(handler func(connection *natsbroker.Conn, err error)) WorkerOption
WithDisconnectErrorHandler sets handler for disconnection from server.
func WithErrorHandler ¶
func WithErrorHandler( handler func(connection *natsbroker.Conn, subscription *natsbroker.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 *natsbroker.Msg)) WorkerOption
WithMessageHandler sets handler for received message.
func WithNatsOptions ¶
func WithNatsOptions(opts ...natsbroker.Option) WorkerOption
WithNatsOptions sets NATS option for connection with broker configuration.