Documentation
¶
Overview ¶
Package broker defines standard interface for a message broker.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var File_broker_proto protoreflect.FileDescriptor
Functions ¶
This section is empty.
Types ¶
type Broker ¶
type Broker interface { // Open establish connection to the target server. Open(ctx context.Context) error // Publish publish the message to the target topic. Publish(ctx context.Context, topic string, m *Message, opts ...PublishOption) error // Subscribe subscribe to the topic to consume messages. Subscribe(ctx context.Context, topic string, h Handler, opts ...SubscribeOption) (Subscriber, error) // Close flush all in-flight messages and close underlying connection. // Close allows a context to control the duration // of a flush/close call. This context should be non-nil. // If a deadline is not set, a default deadline of 5s will be applied. Close(context.Context) error }
Broker is an interface used for asynchronous messaging.
type Event ¶
type Event interface { Topic() string Message() *Message Ack() error Error() error Reason() Reason }
Event is given to a subscription handler for processing
type Handler ¶
Handler is used to process messages via a subscription of a topic. The handler is passed a publication interface which contains the message and optional Ack method to acknowledge receipt of the message.
type Message ¶
type Message struct { Header map[string]string `` /* 153-byte string literal not displayed */ Body []byte `protobuf:"bytes,2,opt,name=body,proto3" json:"body,omitempty"` // contains filtered or unexported fields }
func (*Message) Descriptor
deprecated
func (*Message) ProtoMessage ¶
func (*Message) ProtoMessage()
func (*Message) ProtoReflect ¶
func (x *Message) ProtoReflect() protoreflect.Message
type PublishOption ¶
type PublishOption func(*PublishOptions)
PublishOption is a func for config publish options.
type PublishOptions ¶
type PublishOptions struct { }
PublishOptions is a configuration holder for publish options.
type SubscribeOption ¶
type SubscribeOption func(*SubscribeOptions)
SubscribeOption is a func for config subscription.
func DisableAutoAck ¶
func DisableAutoAck() SubscribeOption
DisableAutoAck will disable auto ack of messages after they have been handled.
func Queue ¶
func Queue(name string) SubscribeOption
Queue sets the name of the queue to share messages on
type SubscribeOptions ¶
type SubscribeOptions struct { // AutoAck defaults to true. When a handler returns // with a nil error the message is acked. AutoAck bool // Subscribers with the same queue name // will create a shared subscription where each // receives a subset of messages. Queue string }
SubscribeOptions is a configuration holder for subscriptions.
func (*SubscribeOptions) Apply ¶
func (op *SubscribeOptions) Apply(opts ...SubscribeOption)
Apply apply the options.
type Subscriber ¶
Subscriber is a convenience return type for the Subscribe method