Update the broker interface

This commit is contained in:
Asim
2015-12-23 19:07:26 +00:00
parent 6226a80e78
commit 02aca819d7
3 changed files with 102 additions and 18 deletions

47
broker/options.go Normal file
View File

@@ -0,0 +1,47 @@
package broker
type Options struct{}
type PublishOptions struct{}
type SubscribeOptions struct {
// AutoAck defaults to true
AutoAck bool
// NumHandlers defaults to 1
NumHandlers int
}
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
}
}
// NumHandlers sets the number of concurrent handlers to create
// for a subscriber.
func NumHandlers(i int) SubscribeOption {
return func(o *SubscribeOptions) {
o.NumHandlers = i
}
}
func newSubscribeOptions(opts ...SubscribeOption) SubscribeOptions {
opt := SubscribeOptions{
AutoAck: true,
NumHandlers: 1,
}
for _, o := range opts {
o(&opt)
}
return opt
}