-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoptions.go
63 lines (54 loc) · 1.93 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
package subee
import "time"
// Option configures Config.
type Option func(*Config)
// WithConsumerInterceptors returns an Option that sets the ConsumerInterceptor implementations(s).
// Interceptors are called in order of addition.
// e.g) interceptor1, interceptor2, interceptor3 => interceptor1 => interceptor2 => interceptor3 => Consumer.Consume
func WithConsumerInterceptors(interceptors ...ConsumerInterceptor) Option {
return func(c *Config) {
c.ConsumerInterceptors = append(c.ConsumerInterceptors, interceptors...)
}
}
// WithBatchConsumerInterceptors returns an Option that sets the BatchConsumerInterceptor implementations(s).
// Interceptors are called in order of addition.
// e.g) interceptor1, interceptor2, interceptor3 => interceptor1 => interceptor2 => interceptor3 => BatchConsumer.Consume
func WithBatchConsumerInterceptors(interceptors ...BatchConsumerInterceptor) Option {
return func(c *Config) {
c.BatchConsumerInterceptors = append(c.BatchConsumerInterceptors, interceptors...)
}
}
// WithLogger returns an Option that sets the Logger implementation.
func WithLogger(logger Logger) Option {
return func(c *Config) {
c.Logger = logger
}
}
// WithStatsHandler returns an Option that sets the StatsHandler implementation.
func WithStatsHandler(sh StatsHandler) Option {
return func(c *Config) {
c.StatsHandler = sh
}
}
// WithChunkSize returns an Option that sets the maximum chunked message size per consuming.
func WithChunkSize(size int) Option {
return func(c *Config) {
if size > 0 {
c.ChunkSize = size
}
}
}
// WithFlushInterval returns an Option that sets the maximum flush time interval to receive message.
func WithFlushInterval(inval time.Duration) Option {
return func(c *Config) {
if inval > 0 {
c.FlushInterval = inval
}
}
}
// WithAckImmediately returns an Option that make ack messages before consuming.
func WithAckImmediately() Option {
return func(c *Config) {
c.AckImmediately = true
}
}