forked from st3v/go-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
69 lines (61 loc) · 2.08 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
57
58
59
60
61
62
63
64
65
66
67
68
69
package sqs
import (
"github.com/micro/go-micro/broker"
"golang.org/x/net/context"
)
type dedupFunctionKey struct{}
type groupIdFunctionKey struct{}
type maxMessagesKey struct{}
type visiblityTimeoutKey struct{}
type waitTimeSecondsKey struct{}
type StringFromMessageFunc func(m *broker.Message) string
// DeduplicationFunction sets the function used to create the deduplication string
// for a given message
func DeduplicationFunction(dedup StringFromMessageFunc) broker.Option {
return func(o *broker.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, dedupFunctionKey{}, dedup)
}
}
// GroupIDFunction sets the function used to create the group ID string for a
// given message
func GroupIDFunction(groupfunc StringFromMessageFunc) broker.Option {
return func(o *broker.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, groupIdFunctionKey{}, groupfunc)
}
}
// MaxReceiveMessages indicates how many messages a receive operation should pull
// during any single call
func MaxReceiveMessages(max int64) broker.SubscribeOption {
return func(o *broker.SubscribeOptions) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, maxMessagesKey{}, max)
}
}
// VisibilityTimeout controls how long a message is hidden from other queue consumers
// before being put back. If a consumer does not delete the message, it will be put back
// even if it was "processed"
func VisibilityTimeout(seconds int64) broker.SubscribeOption {
return func(o *broker.SubscribeOptions) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, visiblityTimeoutKey{}, seconds)
}
}
// WaitTimeSeconds controls the length of long polling for available messages
func WaitTimeSeconds(seconds int64) broker.SubscribeOption {
return func(o *broker.SubscribeOptions) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, waitTimeSecondsKey{}, seconds)
}
}