micro/broker/options.go

59 lines
1.2 KiB
Go

package broker
type Options struct {
// Other options to be used by broker implementations
Options map[string]string
}
type PublishOptions struct {
// Other options to be used by broker implementations
Options map[string]string
}
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
// Other options to be used by broker implementations
Options map[string]string
}
type Option func(*Options)
type PublishOption func(*PublishOptions)
type SubscribeOption func(*SubscribeOptions)
// DisableAutoAck will disable auto acking of messages
// after they have been handled.
func DisableAutoAck() SubscribeOption {
return func(o *SubscribeOptions) {
o.AutoAck = false
}
}
// QueueName sets the name of the queue to share messages on
func QueueName(name string) SubscribeOption {
return func(o *SubscribeOptions) {
o.Queue = name
}
}
func newSubscribeOptions(opts ...SubscribeOption) SubscribeOptions {
opt := SubscribeOptions{
AutoAck: true,
}
for _, o := range opts {
o(&opt)
}
return opt
}