Documentation ¶
Overview ¶
Package mq provides standard way to deal with messaging queue system.
Index ¶
- func ContextWithMaxOutstanding(ctx context.Context, v int) context.Context
- func ContextWithNumWorkers(ctx context.Context, v int) context.Context
- func MaxOutstandingFromContext(ctx context.Context) (int, bool)
- func NumWorkersFromContext(ctx context.Context) (int, bool)
- type AckErrNotifier
- type AckHandler
- type Handler
- type HandlerFunc
- type Message
- type NackErrNotifier
- type PublishResult
- type Publisher
- type Subscriber
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithMaxOutstanding ¶
ContextWithMaxOutstanding decorate ctx with maxOutstanding value.
func ContextWithNumWorkers ¶
ContextWithNumWorkers decorate ctx with numWorkers value.
func MaxOutstandingFromContext ¶
MaxOutstandingFromContext get value of maxOutstanding from context.
Types ¶
type AckErrNotifier ¶
AckErrNotifier provides method NotifyAckErr, invokes when Ack failed.
type AckHandler ¶
type AckHandler interface { // HandleAck handle message that automatically ack when nil error returned. HandleAck(Message) error }
AckHandler handle message and ack automatically.
type Handler ¶
type Handler interface {
Handle(Message)
}
Handler is the message handler.
func AutoAck ¶
func AutoAck(h AckHandler) Handler
AutoAck creates Handler from AckHandler.
AutoAck will handle the message, when err returned by AckHandler then it will m.Nack() otherwise m.Ack(). To know the successful of Ack and Nack, the h should also implement the AckErrNotifier and NackErrNotifier. Implementing these interfaces are optional.
type NackErrNotifier ¶
NackErrNotifier provides method NotifyNackErr, invokes when Nack failed.
type PublishResult ¶
type PublishResult interface { Get(context.Context) (id string, err error) Ready() <-chan struct{} }
PublishResult is results of the publish.
type Publisher ¶
type Publisher interface {
Publish(topic string, msg []byte) PublishResult
}
Publisher is the interface that wraps the basic Publish method.
Publish publishes the msg to specific topic.
type Subscriber ¶
Subscriber is the interface that wraps the basic Subscribe method.
Subscribe subscribes to a channel for receive messages. The message will be passed to h Handler. Message handling need to be Ack or Nack. Leave the Nack might block the receiving until timeout (the behaviour will differ based on implementation).