-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
options.go
76 lines (55 loc) · 1.94 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
70
71
72
73
74
75
76
package stan
import (
"context"
"time"
"github.com/micro/go-micro/v2/broker"
"github.com/micro/go-micro/v2/server"
stan "github.com/nats-io/stan.go"
)
type optionsKey struct{}
// Options accepts stan.Options
func Options(opts stan.Options) broker.Option {
return setBrokerOption(optionsKey{}, opts)
}
type clusterIDKey struct{}
// ClusterID specify cluster id to connect
func ClusterID(clusterID string) broker.Option {
return setBrokerOption(clusterIDKey{}, clusterID)
}
type clientIDKey struct{}
// ClientID specify client id to connect
func ClientID(clientID string) broker.Option {
return setBrokerOption(clientIDKey{}, clientID)
}
type subscribeOptionKey struct{}
func SubscribeOption(opts ...stan.SubscriptionOption) broker.SubscribeOption {
return setSubscribeOption(subscribeOptionKey{}, opts)
}
func ServerSubscriberOption(opts ...stan.SubscriptionOption) server.SubscriberOption {
return setServerSubscriberOption(subscribeOptionKey{}, opts)
}
type subscribeContextKey struct{}
// SubscribeContext set the context for broker.SubscribeOption
func SubscribeContext(ctx context.Context) broker.SubscribeOption {
return setSubscribeOption(subscribeContextKey{}, ctx)
}
type ackSuccessKey struct{}
// AckOnSuccess will automatically acknowledge messages when no error is returned
func AckOnSuccess() broker.SubscribeOption {
return setSubscribeOption(ackSuccessKey{}, true)
}
type connectTimeoutKey struct{}
// ConnectTimeout timeout for connecting to broker -1 infinitive or time.Duration value
func ConnectTimeout(td time.Duration) broker.Option {
return setBrokerOption(connectTimeoutKey{}, td)
}
type connectRetryKey struct{}
// ConnectRetry reconnect to broker in case of errors
func ConnectRetry(v bool) broker.Option {
return setBrokerOption(connectRetryKey{}, v)
}
type durableKey struct{}
// DurableName sets the DurableName for the subscriber
func DurableName(name string) broker.Option {
return setBrokerOption(durableKey{}, name)
}