generated from nano-interactive/go-library-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
83 lines (68 loc) · 1.86 KB
/
config.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
77
78
79
80
81
82
83
package consumer
import (
"context"
"github.com/rabbitmq/amqp091-go"
"github.com/nano-interactive/go-amqp/v3/connection"
"github.com/nano-interactive/go-amqp/v3/serializer"
)
type ExchangeBinding struct {
ExchangeName string
RoutingKey string
}
type QueueDeclare struct {
QueueName string
ExchangeBindings []ExchangeBinding
Durable bool
AutoDelete bool
Exclusive bool
NoWait bool
}
type Config[T any] struct {
serializer serializer.Serializer[T]
onError connection.OnErrorFunc
onMessageError func(context.Context, *amqp091.Delivery, error)
onListenerStart func(context.Context, int)
onListenerExit func(context.Context, int)
connectionOptions connection.Config
queueConfig QueueConfig
retryCount uint32
}
type Option[T any] func(*Config[T])
func WithMessageDeserializer[T any](serializer serializer.Serializer[T]) Option[T] {
return func(c *Config[T]) {
c.serializer = serializer
}
}
func WithRetryMessageCountCount[T any](count uint32) Option[T] {
return func(c *Config[T]) {
c.retryCount = count
}
}
func WithOnListenerStart[T any](onListenerStart func(context.Context, int)) Option[T] {
return func(c *Config[T]) {
c.onListenerStart = onListenerStart
}
}
func WithOnListenerExit[T any](onListenerExit func(context.Context, int)) Option[T] {
return func(c *Config[T]) {
c.onListenerExit = onListenerExit
}
}
func WithOnMessageError[T any](onMessageError func(context.Context, *amqp091.Delivery, error)) Option[T] {
return func(c *Config[T]) {
c.onMessageError = onMessageError
}
}
func WithQueueConfig[T any](cfg QueueConfig) Option[T] {
return func(c *Config[T]) {
if cfg.Workers == 0 {
cfg.Workers = 1
}
c.queueConfig = cfg
}
}
func WithOnErrorFunc[T any](onError connection.OnErrorFunc) Option[T] {
return func(c *Config[T]) {
c.onError = onError
}
}