forked from st3v/go-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
41 lines (35 loc) · 983 Bytes
/
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
package rabbitmq
import (
"context"
"github.com/micro/go-micro/broker"
)
type durableQueueKey struct{}
type headersKey struct{}
type exchangeKey struct{}
// DurableQueue creates a durable queue when subscribing.
func DurableQueue() broker.SubscribeOption {
return func(o *broker.SubscribeOptions) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, durableQueueKey{}, true)
}
}
// Headers adds headers used by the headers exchange
func Headers(h map[string]interface{}) broker.SubscribeOption {
return func(o *broker.SubscribeOptions) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, headersKey{}, h)
}
}
// Exchange is an option to set the Exchange
func Exchange(e string) broker.Option {
return func(o *broker.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, exchangeKey{}, e)
}
}