@@ -93,12 +93,13 @@ options() -> [
93
93
{bindings , string_list , undefined },
94
94
{qx_name , string , undefined }, % % not used currently
95
95
{queue , any , undefined },
96
- {queue_type , string , <<>> },
97
- {takeover , boolean , false },
96
+ {queue_type , string , { rabbitmq , queue_type } },
97
+ {takeover , boolean , { rabbitmq , takeover } },
98
98
{takeover_timeout , duration , <<" 5m" >>},
99
99
{takeover_queue , string , undefined },
100
- {takeover_queue_prefix , string , {rabbitmq , queue_prefix }},
101
- {takeover_queue_type , string , <<>>},
100
+ {takeover_queue_prefix , string , {rabbitmq , takeover_queue_prefix }},
101
+ {takeover_queue_type , string , {rabbitmq , takeover_queue_type }},
102
+ % % defaults to "vhost"
102
103
{takeover_queue_vhost , string , undefined },
103
104
{queue_prefix , string , {rabbitmq , queue_prefix }},
104
105
{consumer_tag , string , undefined },
@@ -136,7 +137,7 @@ metrics() ->
136
137
].
137
138
138
139
init ({GraphId , NodeId } = Idx , _Ins ,
139
- #{ host := Host0 , port := Port , user := _User , pass := _Pass , vhost := _VHost , queue := Q0 , queue_type := QType0 ,
140
+ #{ host := Host0 , port := Port , user := _User , pass := _Pass , vhost := VHost , queue := Q0 , queue_type := QType0 ,
140
141
exchange := Ex0 , qx_name := _QxName , prefetch := Prefetch , routing_key := RoutingKey0 , bindings := Bindings0 ,
141
142
dt_field := DTField , dt_format := DTFormat , ssl := UseSSL , include_topic := IncludeTopic ,
142
143
topic_as := TopicKey , ack_every := AckEvery0 , ack_after := AckTimeout0 , as := As , consumer_tag := CTag0 ,
@@ -149,10 +150,10 @@ init({GraphId, NodeId} = Idx, _Ins,
149
150
'_parent_pid' := ParentPid , '_parent_subscriptions' := ParentSubs , passive := Passive
150
151
} = Opts0 ) ->
151
152
152
- % % lager:warning("init ~p", [Idx]),
153
-
153
+ % % lager:warning("opts ~p", [Opts0]),
154
154
Q = eval_name (Q0 , Opts0 , Idx ),
155
- QType = binary_to_list (QType0 ),
155
+ QName = faxe_util :prefix_binary (Q , QPrefix ),
156
+ QType = faxe_util :to_list (QType0 ),
156
157
CTag = case CTag0 of undefined -> <<" c_" , GraphId /binary , " _" , NodeId /binary >>; _ -> CTag0 end ,
157
158
State0 = # state {
158
159
include_topic = IncludeTopic , topic_key = TopicKey , as = As , dedup_queue = memory_queue :new (DedupSize ),
@@ -169,17 +170,27 @@ init({GraphId, NodeId} = Idx, _Ins,
169
170
true ->
170
171
TakeoverQ1 = eval_name (TakeoverQ0 , Opts0 , Idx ),
171
172
TakeoverQ2 = faxe_util :prefix_binary (TakeoverQ1 , TakeoverQPrefix ),
173
+
172
174
TakeoverTime = faxe_time :duration_to_ms (TakeoverTimeout ),
173
175
NewTOpts = Opts0 #{takeover_queue => TakeoverQ2 , takeover_time => TakeoverTime },
174
176
TakeoverOpts0 = init_takeover_consumer (self (), Idx , CTag , NewTOpts ),
175
- % % start takeover consumer
176
- State01 = State0 # state {takeover_consumer_opts = TakeoverOpts0 },
177
- TakeoverPid = start_takeover_consumer (State01 ),
178
- TakeoverData = memory_queue :new (DedupSize ),
179
- {TakeoverOpts0 , State01 # state {takeover_consumer_pid = TakeoverPid , takeover_data = TakeoverData }}
177
+ CompQ = #{queue => QName , queue_type => QType , vhost => VHost },
178
+ case check_unique_q (TakeoverOpts0 , CompQ ) of
179
+ true ->
180
+ % % start takeover consumer
181
+ State01 = State0 # state {takeover_consumer_opts = TakeoverOpts0 },
182
+ TakeoverPid = start_takeover_consumer (State01 ),
183
+ TakeoverData = memory_queue :new (DedupSize ),
184
+ {TakeoverOpts0 , State01 # state {takeover_consumer_pid = TakeoverPid , takeover_data = TakeoverData }};
185
+ false ->
186
+ lager :warning (
187
+ " cannot start takeover action, because both queues are the same ~p , will continue without takeover" ,
188
+ [CompQ ]),
189
+ {undefined , State0 }
190
+ end
180
191
end ,
181
192
182
- TakeoverQType = binary_to_list (TakeoverQType0 ),
193
+ TakeoverQType = faxe_util : to_list (TakeoverQType0 ),
183
194
TakeoverQ = case is_map (TakeoverOpts ) andalso is_map_key (queue , TakeoverOpts ) of
184
195
true -> maps :get (queue , TakeoverOpts );
185
196
false -> undefined
@@ -192,7 +203,7 @@ init({GraphId, NodeId} = Idx, _Ins,
192
203
193
204
Host = binary_to_list (Host0 ),
194
205
% % lager:info("opts before: ~p",[Opts0]),
195
- QName = faxe_util : prefix_binary ( Q , QPrefix ),
206
+
196
207
Opts = Opts0 #{
197
208
host => Host , consumer_tag => CTag ,
198
209
exchange => faxe_util :prefix_binary (Ex , XPrefix ),
@@ -201,7 +212,7 @@ init({GraphId, NodeId} = Idx, _Ins,
201
212
routing_key => faxe_util :to_rkey (RoutingKey0 ),
202
213
bindings => faxe_util :to_rkey (Bindings0 )
203
214
},
204
- % % lager:info("opts: ~p",[Opts]),
215
+ lager :info (" opts: ~p " ,[Opts ]),
205
216
206
217
State = State1 # state {
207
218
opts = Opts , ack_after = AckTimeout , queue_type = QType ,
@@ -217,6 +228,12 @@ init({GraphId, NodeId} = Idx, _Ins,
217
228
218
229
{ok , start_consumer (NewState )}.
219
230
231
+ check_unique_q (#{queue := Q , queue_type := QType , vhost := VHost }, #{queue := Q , queue_type := QType , vhost := VHost }) ->
232
+ false ;
233
+ check_unique_q (_ , _ ) ->
234
+ true .
235
+
236
+
220
237
init_takeover_consumer (ParentPid , IdxParent , CTag ,
221
238
Opts = #{takeover_queue := Q0 , takeover_queue_type := QType0 , '_name' := Name , takeover_queue_vhost := TVHost ,
222
239
vhost := VHost }) ->
@@ -228,7 +245,7 @@ init_takeover_consumer(ParentPid, IdxParent, CTag,
228
245
use_flow_ack => false ,
229
246
% % for the takeover-consumer, the takeover options become the "normal" q opts
230
247
queue => Q0 ,
231
- queue_type => QType0 ,
248
+ queue_type => faxe_util : to_list ( QType0 ) ,
232
249
vhost => TakeoverVHost ,
233
250
% % cannot use queue prefix
234
251
queue_prefix => <<>>,
0 commit comments