Skip to content

Commit e01dc98

Browse files
committed
Check queue existence when checking for fake bindings existence.
rabbit_binding:exists checks bindings table. Since default bindings are not in that table anymore, it should check for queue existence.
1 parent c7d107d commit e01dc98

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

src/rabbit_binding.erl

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
-export([has_for_source/1, remove_for_source/1,
2828
remove_for_destination/2, remove_transient_for_destination/1]).
2929

30+
-define(DEFAULT_EXCHANGE(VHostPath), #resource{virtual_host = VHostPath,
31+
kind = exchange,
32+
name = <<>>}).
33+
3034
%%----------------------------------------------------------------------------
3135

3236
-export_type([key/0, deletions/0]).
@@ -156,6 +160,14 @@ recover_semi_durable_route_txn(R = #route{binding = B}, X) ->
156160
(Serial, false) -> x_callback(Serial, X, add_binding, B)
157161
end).
158162

163+
exists(#binding{source = ?DEFAULT_EXCHANGE(_),
164+
destination = #resource{kind = queue, name = QName} = Queue,
165+
key = QName,
166+
args = []}) ->
167+
case rabbit_amqqueue:lookup(Queue) of
168+
{ok, _} -> true;
169+
{error, not_found} -> false
170+
end;
159171
exists(Binding) ->
160172
binding_action(
161173
Binding, fun (_Src, _Dst, B) ->
@@ -247,9 +259,7 @@ list(VHostPath) ->
247259
[B || #route{binding = B} <- mnesia:dirty_match_object(rabbit_route,
248260
Route)].
249261

250-
list_for_source(#resource{kind = exchange,
251-
virtual_host = VHostPath,
252-
name = <<>>}) ->
262+
list_for_source(?DEFAULT_EXCHANGE(VHostPath)) ->
253263
implicit_bindings(VHostPath);
254264
list_for_source(SrcName) ->
255265
mnesia:async_dirty(
@@ -273,33 +283,30 @@ list_for_destination(DstName) ->
273283

274284
implicit_bindings(VHostPath) ->
275285
DstQueues = rabbit_amqqueue:list_names(VHostPath),
276-
DefaultExchange = #resource{virtual_host = VHostPath,
277-
kind = exchange,
278-
name = <<>>},
279-
[ #binding{source = DefaultExchange,
286+
[ #binding{source = ?DEFAULT_EXCHANGE(VHostPath),
280287
destination = DstQueue,
281-
key = QName}
288+
key = QName,
289+
args = []}
282290
|| DstQueue = #resource{name = QName} <- DstQueues ].
283291

284292
implicit_for_destination(DstQueue = #resource{kind = queue,
285293
virtual_host = VHostPath,
286294
name = QName}) ->
287-
DefaultExchange = #resource{virtual_host = VHostPath,
288-
kind = exchange,
289-
name = <<>>},
290-
[#binding{source = DefaultExchange,
295+
[#binding{source = ?DEFAULT_EXCHANGE(VHostPath),
291296
destination = DstQueue,
292-
key = QName}];
297+
key = QName,
298+
args = []}];
293299
implicit_for_destination(_) ->
294300
[].
295301

296-
list_for_source_and_destination(#resource{kind = exchange,
297-
virtual_host = VHostPath,
298-
name = <<>>} = DefaultExchange,
302+
list_for_source_and_destination(?DEFAULT_EXCHANGE(VHostPath),
299303
#resource{kind = queue,
300304
virtual_host = VHostPath,
301305
name = QName} = DstQueue) ->
302-
[#binding{source = DefaultExchange, destination = DstQueue, key = QName}];
306+
[#binding{source = ?DEFAULT_EXCHANGE(VHostPath),
307+
destination = DstQueue,
308+
key = QName,
309+
args = []}];
303310
list_for_source_and_destination(SrcName, DstName) ->
304311
mnesia:async_dirty(
305312
fun() ->

0 commit comments

Comments
 (0)