-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathoption.go
43 lines (36 loc) · 1.12 KB
/
option.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
package ekafka
import (
"github.com/segmentio/kafka-go"
)
type Balancer = kafka.Balancer
// WithClientInterceptor 注入拦截器
func WithClientInterceptor(interceptors ...ClientInterceptor) Option {
return func(c *Container) {
c.config.clientInterceptors = append(c.config.clientInterceptors, interceptors...)
}
}
// WithServerInterceptor 注入拦截器
func WithServerInterceptor(interceptors ...ServerInterceptor) Option {
return func(c *Container) {
c.config.serverInterceptors = append(c.config.serverInterceptors, interceptors...)
}
}
// WithDebug 注入Debug配置
func WithDebug(debug bool) Option {
return func(c *Container) {
c.config.Debug = debug
}
}
// WithBrokers 注入brokers配置
func WithBrokers(brokers ...string) Option {
return func(c *Container) {
c.config.Brokers = brokers
}
}
// WithRegisterBalancer 注册名字为<balancerName>的balancer
// 注册之后可通过在producer配置文件中可通过<balancerName>来指定使用此balancer
func WithRegisterBalancer(balancerName string, balancer Balancer) Option {
return func(c *Container) {
c.config.balancers[balancerName] = balancer
}
}