Documentation ¶
Overview ¶
Package pubsub provides the nats client to connect and consume subscriptions messages
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMsgHandlerNotRegistered is returned when the message handler callback is not registered ErrMsgHandlerNotRegistered = errors.New("nats message handler callback is not registered") )
Functions ¶
This section is empty.
Types ¶
type MsgHandler ¶
type MsgHandler func(msg events.Message[events.ChangeMessage]) error
MsgHandler is a callback function that processes messages delivered to subscribers
type Subscriber ¶
type Subscriber struct {
// contains filtered or unexported fields
}
Subscriber is the subscriber client
func NewSubscriber ¶
func NewSubscriber(ctx context.Context, connection events.Connection, opts ...SubscriberOption) *Subscriber
NewSubscriber creates a new Subscriber
func (Subscriber) Listen ¶
func (s Subscriber) Listen() error
Listen start listening for messages on registered subjects and calls the registered message handler
func (*Subscriber) Subscribe ¶
func (s *Subscriber) Subscribe(topic string) error
Subscribe subscribes to a nats subject
type SubscriberOption ¶
type SubscriberOption func(s *Subscriber)
SubscriberOption is a functional option for the Subscriber
func WithLogger ¶
func WithLogger(l *zap.SugaredLogger) SubscriberOption
WithLogger sets the logger for the Subscriber
func WithMaxMsgProcessAttempts ¶ added in v0.0.8
func WithMaxMsgProcessAttempts(max uint64) SubscriberOption
WithMaxMsgProcessAttempts sets the maximum number of times a message will attempt to process before being terminated
func WithMsgHandler ¶
func WithMsgHandler(cb MsgHandler) SubscriberOption
WithMsgHandler sets the message handler callback for the Subscriber