@@ -3,14 +3,25 @@ package rabbitmq
3
3
// getDefaultConsumeOptions descibes the options that will be used when a value isn't provided
4
4
func getDefaultConsumeOptions () ConsumeOptions {
5
5
return ConsumeOptions {
6
- QueueDurable : false ,
7
- QueueAutoDelete : false ,
8
- QueueExclusive : false ,
9
- QueueNoWait : false ,
10
- QueueArgs : nil ,
11
- BindingExchange : nil ,
12
- BindingNoWait : false ,
13
- BindingArgs : nil ,
6
+ QueueDeclare : QueueDeclareOptions {
7
+ QueueName : "" ,
8
+ QueueDurable : false ,
9
+ QueueAutoDelete : false ,
10
+ QueueExclusive : false ,
11
+ QueueNoWait : false ,
12
+ QueueArgs : nil ,
13
+ },
14
+ BindingExchange : BindingExchangeOptions {
15
+ Name : "" ,
16
+ Kind : "" ,
17
+ Durable : false ,
18
+ AutoDelete : false ,
19
+ Internal : false ,
20
+ NoWait : false ,
21
+ BindingNoWait : false ,
22
+ BindingArgs : nil ,
23
+ ExchangeArgs : nil ,
24
+ },
14
25
Concurrency : 1 ,
15
26
QOSPrefetch : 0 ,
16
27
QOSGlobal : false ,
@@ -25,14 +36,8 @@ func getDefaultConsumeOptions() ConsumeOptions {
25
36
26
37
// ConsumeOptions are used to describe how a new consumer will be created.
27
38
type ConsumeOptions struct {
28
- QueueDurable bool
29
- QueueAutoDelete bool
30
- QueueExclusive bool
31
- QueueNoWait bool
32
- QueueArgs Table
33
- BindingExchange * BindingExchangeOptions
34
- BindingNoWait bool
35
- BindingArgs Table
39
+ QueueDeclare QueueDeclareOptions
40
+ BindingExchange BindingExchangeOptions
36
41
Concurrency int
37
42
QOSPrefetch int
38
43
QOSGlobal bool
@@ -44,119 +49,6 @@ type ConsumeOptions struct {
44
49
ConsumerArgs Table
45
50
}
46
51
47
- // getBindingExchangeOptionsOrSetDefault returns pointer to current BindingExchange options. if no BindingExchange options are set yet, it will set it with default values.
48
- func getBindingExchangeOptionsOrSetDefault (options * ConsumeOptions ) * BindingExchangeOptions {
49
- if options .BindingExchange == nil {
50
- options .BindingExchange = & BindingExchangeOptions {
51
- Name : "" ,
52
- Kind : "direct" ,
53
- Durable : false ,
54
- AutoDelete : false ,
55
- Internal : false ,
56
- NoWait : false ,
57
- ExchangeArgs : nil ,
58
- }
59
- }
60
- return options .BindingExchange
61
- }
62
-
63
- // BindingExchangeOptions are used when binding to an exchange.
64
- // it will verify the exchange is created before binding to it.
65
- type BindingExchangeOptions struct {
66
- Name string
67
- Kind string
68
- Durable bool
69
- AutoDelete bool
70
- Internal bool
71
- NoWait bool
72
- ExchangeArgs Table
73
- }
74
-
75
- // WithConsumeOptionsQueueDurable sets the queue to durable, which means it won't
76
- // be destroyed when the server restarts. It must only be bound to durable exchanges
77
- func WithConsumeOptionsQueueDurable (options * ConsumeOptions ) {
78
- options .QueueDurable = true
79
- }
80
-
81
- // WithConsumeOptionsQueueAutoDelete sets the queue to auto delete, which means it will
82
- // be deleted when there are no more conusmers on it
83
- func WithConsumeOptionsQueueAutoDelete (options * ConsumeOptions ) {
84
- options .QueueAutoDelete = true
85
- }
86
-
87
- // WithConsumeOptionsQueueExclusive sets the queue to exclusive, which means
88
- // it's are only accessible by the connection that declares it and
89
- // will be deleted when the connection closes. Channels on other connections
90
- // will receive an error when attempting to declare, bind, consume, purge or
91
- // delete a queue with the same name.
92
- func WithConsumeOptionsQueueExclusive (options * ConsumeOptions ) {
93
- options .QueueExclusive = true
94
- }
95
-
96
- // WithConsumeOptionsQueueNoWait sets the queue to nowait, which means
97
- // the queue will assume to be declared on the server. A
98
- // channel exception will arrive if the conditions are met for existing queues
99
- // or attempting to modify an existing queue from a different connection.
100
- func WithConsumeOptionsQueueNoWait (options * ConsumeOptions ) {
101
- options .QueueNoWait = true
102
- }
103
-
104
- // WithConsumeOptionsQuorum sets the queue a quorum type, which means multiple nodes
105
- // in the cluster will have the messages distributed amongst them for higher reliability
106
- func WithConsumeOptionsQuorum (options * ConsumeOptions ) {
107
- if options .QueueArgs == nil {
108
- options .QueueArgs = Table {}
109
- }
110
- options .QueueArgs ["x-queue-type" ] = "quorum"
111
- }
112
-
113
- // WithConsumeOptionsBindingExchangeName returns a function that sets the exchange name the queue will be bound to
114
- func WithConsumeOptionsBindingExchangeName (name string ) func (* ConsumeOptions ) {
115
- return func (options * ConsumeOptions ) {
116
- getBindingExchangeOptionsOrSetDefault (options ).Name = name
117
- }
118
- }
119
-
120
- // WithConsumeOptionsBindingExchangeKind returns a function that sets the binding exchange kind/type
121
- func WithConsumeOptionsBindingExchangeKind (kind string ) func (* ConsumeOptions ) {
122
- return func (options * ConsumeOptions ) {
123
- getBindingExchangeOptionsOrSetDefault (options ).Kind = kind
124
- }
125
- }
126
-
127
- // WithConsumeOptionsBindingExchangeDurable returns a function that sets the binding exchange durable flag
128
- func WithConsumeOptionsBindingExchangeDurable (options * ConsumeOptions ) {
129
- getBindingExchangeOptionsOrSetDefault (options ).Durable = true
130
- }
131
-
132
- // WithConsumeOptionsBindingExchangeAutoDelete returns a function that sets the binding exchange autoDelete flag
133
- func WithConsumeOptionsBindingExchangeAutoDelete (options * ConsumeOptions ) {
134
- getBindingExchangeOptionsOrSetDefault (options ).AutoDelete = true
135
- }
136
-
137
- // WithConsumeOptionsBindingExchangeInternal returns a function that sets the binding exchange internal flag
138
- func WithConsumeOptionsBindingExchangeInternal (options * ConsumeOptions ) {
139
- getBindingExchangeOptionsOrSetDefault (options ).Internal = true
140
- }
141
-
142
- // WithConsumeOptionsBindingExchangeNoWait returns a function that sets the binding exchange noWait flag
143
- func WithConsumeOptionsBindingExchangeNoWait (options * ConsumeOptions ) {
144
- getBindingExchangeOptionsOrSetDefault (options ).NoWait = true
145
- }
146
-
147
- // WithConsumeOptionsBindingExchangeArgs returns a function that sets the binding exchange arguments that are specific to the server's implementation of the exchange
148
- func WithConsumeOptionsBindingExchangeArgs (args Table ) func (* ConsumeOptions ) {
149
- return func (options * ConsumeOptions ) {
150
- getBindingExchangeOptionsOrSetDefault (options ).ExchangeArgs = args
151
- }
152
- }
153
-
154
- // WithConsumeOptionsBindingNoWait sets the bindings to nowait, which means if the queue can not be bound
155
- // the channel will not be closed with an error.
156
- func WithConsumeOptionsBindingNoWait (options * ConsumeOptions ) {
157
- options .BindingNoWait = true
158
- }
159
-
160
52
// WithConsumeOptionsConcurrency returns a function that sets the concurrency, which means that
161
53
// many goroutines will be spawned to run the provided handler on messages
162
54
func WithConsumeOptionsConcurrency (concurrency int ) func (* ConsumeOptions ) {
0 commit comments