-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
56 lines (46 loc) · 1.45 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package pubsub
// SubscribeOptions describes the options for a subscription action.
type SubscribeOptions struct {
// Group subscriptions with the same group name will create a shared
// subscription where each one receives a subset of the published messages.
Group string
// AutoAck defaults to true. When a handler returns with a nil error the
// message is acknowledged.
AutoAck bool
// Metadata other options for concrete implementations of the Broker
// interface can be stored as metadata.
Metadata Metadata
}
// SubscribeOption is a function that configures a SubscribeOptions instance.
type SubscribeOption func(*SubscribeOptions)
// NewSubscribeOptions convenience function for building a SubscribeOptions
// based on given list of options.
func NewSubscribeOptions(opts ...SubscribeOption) SubscribeOptions {
s := &SubscribeOptions{
AutoAck: true,
Metadata: NewMetadata(),
}
for _, o := range opts {
o(s)
}
return *s
}
// DisableAutoAck will disable auto ACKing of messages after they have been
// handled.
func DisableAutoAck() SubscribeOption {
return func(o *SubscribeOptions) {
o.AutoAck = false
}
}
// WithGroup sets the name of the group to share messages on.
func WithGroup(name string) SubscribeOption {
return func(o *SubscribeOptions) {
o.Group = name
}
}
// SubscribeMetadata set subscription metadata.
func SubscribeMetadata(meta Metadata) SubscribeOption {
return func(o *SubscribeOptions) {
o.Metadata = meta
}
}