Documentation
¶
Overview ¶
Package nats provides tools for comfort work during event processing with NATS broker.
Index ¶
- type CommonConsumer
- type CommonPublisher
- type Consumer
- type ConsumerAlreadyRunningError
- type ConsumerAlreadyStoppedError
- type ConsumerOption
- func WithCloseHandler(handler func(connection *natsbroker.Conn)) ConsumerOption
- func WithDisconnectErrorHandler(handler func(connection *natsbroker.Conn, err error)) ConsumerOption
- func WithErrorHandler(...) ConsumerOption
- func WithGoroutinesPoolSize(size int) ConsumerOption
- func WithMessageChannelBufferSize(size int) ConsumerOption
- func WithMessageHandler(handler func(message *natsbroker.Msg)) ConsumerOption
- func WithNatsOptions(opts ...natsbroker.Option) ConsumerOption
- type Publisher
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.
type ConsumerAlreadyRunningError ¶ added in v1.11.0
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 (e ConsumerAlreadyRunningError) Error() string
func (ConsumerAlreadyRunningError) Unwrap ¶ added in v1.11.0
func (e ConsumerAlreadyRunningError) Unwrap() error
type ConsumerAlreadyStoppedError ¶ added in v1.11.0
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 (e ConsumerAlreadyStoppedError) Error() string
func (ConsumerAlreadyStoppedError) Unwrap ¶ added in v1.11.0
func (e ConsumerAlreadyStoppedError) Unwrap() error
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.