/
options.go
71 lines (58 loc) · 1.69 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
package activemq
import (
"crypto/tls"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
"github.com/tx7do/kratos-transport/broker"
)
type ServerOption func(o *Server)
// WithBrokerOptions MQ代理配置
func WithBrokerOptions(opts ...broker.Option) ServerOption {
return func(s *Server) {
s.brokerOpts = append(s.brokerOpts, opts...)
}
}
func WithAddress(addrs []string) ServerOption {
return func(s *Server) {
s.brokerOpts = append(s.brokerOpts, broker.WithAddress(addrs...))
}
}
func WithTLSConfig(c *tls.Config) ServerOption {
return func(s *Server) {
if c != nil {
s.brokerOpts = append(s.brokerOpts, broker.WithEnableSecure(true))
}
s.brokerOpts = append(s.brokerOpts, broker.WithTLSConfig(c))
}
}
func WithCodec(c string) ServerOption {
return func(s *Server) {
s.brokerOpts = append(s.brokerOpts, broker.WithCodec(c))
}
}
// WithEnableKeepAlive enable keep alive
func WithEnableKeepAlive(enable bool) ServerOption {
return func(s *Server) {
s.enableKeepAlive = enable
}
}
func WithGlobalTracerProvider() ServerOption {
return func(s *Server) {
s.brokerOpts = append(s.brokerOpts, broker.WithGlobalTracerProvider())
}
}
func WithGlobalPropagator() ServerOption {
return func(s *Server) {
s.brokerOpts = append(s.brokerOpts, broker.WithGlobalPropagator())
}
}
func WithTracerProvider(provider trace.TracerProvider, tracerName string) ServerOption {
return func(s *Server) {
s.brokerOpts = append(s.brokerOpts, broker.WithTracerProvider(provider, tracerName))
}
}
func WithPropagator(propagators propagation.TextMapPropagator) ServerOption {
return func(s *Server) {
s.brokerOpts = append(s.brokerOpts, broker.WithPropagator(propagators))
}
}