Skip to content

Commit c7d107d

Browse files
committed
Add fake bindings to list functions.
Default bindings are not represented in the mnesia database but still expected in the management UI and the rabbitmqctl command.
1 parent 10013f5 commit c7d107d

File tree

2 files changed

+51
-14
lines changed

2 files changed

+51
-14
lines changed

src/rabbit_amqqueue.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
-export([list/0, list/1, info_keys/0, info/1, info/2, info_all/1, info_all/2,
3030
emit_info_all/5, list_local/1, info_local/1,
3131
emit_info_local/4, emit_info_down/4]).
32-
-export([list_down/1, count/1, list_names/0, list_local_names/0]).
32+
-export([list_down/1, count/1, list_names/0, list_names/1, list_local_names/0]).
3333
-export([list_by_type/1]).
3434
-export([notify_policy_changed/1]).
3535
-export([consumers/1, consumers_all/1, emit_consumers_all/4, consumer_info_keys/0]).
@@ -747,6 +747,8 @@ list() -> mnesia:dirty_match_object(rabbit_queue, #amqqueue{_ = '_'}).
747747

748748
list_names() -> mnesia:dirty_all_keys(rabbit_queue).
749749

750+
list_names(VHost) -> [Q#amqqueue.name || Q <- list(VHost)].
751+
750752
list_local_names() ->
751753
[ Q#amqqueue.name || #amqqueue{state = State, pid = QPid} = Q <- list(),
752754
State =/= crashed, is_local_to_node(QPid, node())].

src/rabbit_binding.erl

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,14 @@ list(VHostPath) ->
243243
destination = VHostResource,
244244
_ = '_'},
245245
_ = '_'},
246-
[B || #route{binding = B} <- mnesia:dirty_match_object(rabbit_route,
247-
Route)].
248-
246+
implicit_bindings(VHostPath) ++
247+
[B || #route{binding = B} <- mnesia:dirty_match_object(rabbit_route,
248+
Route)].
249+
250+
list_for_source(#resource{kind = exchange,
251+
virtual_host = VHostPath,
252+
name = <<>>}) ->
253+
implicit_bindings(VHostPath);
249254
list_for_source(SrcName) ->
250255
mnesia:async_dirty(
251256
fun() ->
@@ -255,16 +260,46 @@ list_for_source(SrcName) ->
255260
end).
256261

257262
list_for_destination(DstName) ->
258-
mnesia:async_dirty(
259-
fun() ->
260-
Route = #route{binding = #binding{destination = DstName,
261-
_ = '_'}},
262-
[reverse_binding(B) ||
263-
#reverse_route{reverse_binding = B} <-
264-
mnesia:match_object(rabbit_reverse_route,
265-
reverse_route(Route), read)]
266-
end).
267-
263+
implicit_for_destination(DstName) ++
264+
mnesia:async_dirty(
265+
fun() ->
266+
Route = #route{binding = #binding{destination = DstName,
267+
_ = '_'}},
268+
[reverse_binding(B) ||
269+
#reverse_route{reverse_binding = B} <-
270+
mnesia:match_object(rabbit_reverse_route,
271+
reverse_route(Route), read)]
272+
end).
273+
274+
implicit_bindings(VHostPath) ->
275+
DstQueues = rabbit_amqqueue:list_names(VHostPath),
276+
DefaultExchange = #resource{virtual_host = VHostPath,
277+
kind = exchange,
278+
name = <<>>},
279+
[ #binding{source = DefaultExchange,
280+
destination = DstQueue,
281+
key = QName}
282+
|| DstQueue = #resource{name = QName} <- DstQueues ].
283+
284+
implicit_for_destination(DstQueue = #resource{kind = queue,
285+
virtual_host = VHostPath,
286+
name = QName}) ->
287+
DefaultExchange = #resource{virtual_host = VHostPath,
288+
kind = exchange,
289+
name = <<>>},
290+
[#binding{source = DefaultExchange,
291+
destination = DstQueue,
292+
key = QName}];
293+
implicit_for_destination(_) ->
294+
[].
295+
296+
list_for_source_and_destination(#resource{kind = exchange,
297+
virtual_host = VHostPath,
298+
name = <<>>} = DefaultExchange,
299+
#resource{kind = queue,
300+
virtual_host = VHostPath,
301+
name = QName} = DstQueue) ->
302+
[#binding{source = DefaultExchange, destination = DstQueue, key = QName}];
268303
list_for_source_and_destination(SrcName, DstName) ->
269304
mnesia:async_dirty(
270305
fun() ->

0 commit comments

Comments
 (0)