2015-12-23 22:07:26 +03:00
|
|
|
package broker
|
|
|
|
|
2015-12-31 21:11:46 +03:00
|
|
|
type Options struct {
|
|
|
|
|
|
|
|
// Other options to be used by broker implementations
|
|
|
|
Options map[string]string
|
|
|
|
}
|
2015-12-23 22:07:26 +03:00
|
|
|
|
2015-12-31 21:14:40 +03:00
|
|
|
type PublishOptions struct {
|
|
|
|
// Other options to be used by broker implementations
|
|
|
|
Options map[string]string
|
|
|
|
}
|
2015-12-23 22:07:26 +03:00
|
|
|
|
|
|
|
type SubscribeOptions struct {
|
2015-12-23 23:26:13 +03:00
|
|
|
// AutoAck defaults to true. When a handler returns
|
|
|
|
// with a nil error the message is acked.
|
2015-12-23 22:07:26 +03:00
|
|
|
AutoAck bool
|
2015-12-23 23:05:47 +03:00
|
|
|
// Subscribers with the same queue name
|
|
|
|
// will create a shared subscription where each
|
|
|
|
// receives a subset of messages.
|
|
|
|
Queue string
|
2015-12-31 21:14:40 +03:00
|
|
|
|
|
|
|
// Other options to be used by broker implementations
|
|
|
|
Options map[string]string
|
2015-12-23 22:07:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-23 23:26:13 +03:00
|
|
|
// QueueName sets the name of the queue to share messages on
|
2015-12-23 23:05:47 +03:00
|
|
|
func QueueName(name string) SubscribeOption {
|
|
|
|
return func(o *SubscribeOptions) {
|
|
|
|
o.Queue = name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-23 22:07:26 +03:00
|
|
|
func newSubscribeOptions(opts ...SubscribeOption) SubscribeOptions {
|
|
|
|
opt := SubscribeOptions{
|
2015-12-23 23:26:13 +03:00
|
|
|
AutoAck: true,
|
2015-12-23 22:07:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, o := range opts {
|
|
|
|
o(&opt)
|
|
|
|
}
|
|
|
|
|
|
|
|
return opt
|
|
|
|
}
|