diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_binding.erl | 20 | ||||
| -rw-r--r-- | src/rabbit_definitions.erl | 23 |
2 files changed, 36 insertions, 7 deletions
diff --git a/src/rabbit_binding.erl b/src/rabbit_binding.erl index 94b8870192..881374a4aa 100644 --- a/src/rabbit_binding.erl +++ b/src/rabbit_binding.erl @@ -18,9 +18,9 @@ -include_lib("rabbit_common/include/rabbit.hrl"). -include("amqqueue.hrl"). --export([recover/0, recover/2, exists/1, add/2, add/3, remove/1, remove/3, list/1]). --export([list_for_source/1, list_for_destination/1, - list_for_source_and_destination/2]). +-export([recover/0, recover/2, exists/1, add/2, add/3, remove/1, remove/3]). +-export([list/1, list_for_source/1, list_for_destination/1, + list_for_source_and_destination/2, list_explicit/0]). -export([new_deletions/0, combine_deletions/2, add_deletion/3, process_deletions/2]). -export([info_keys/0, info/1, info/2, info_all/1, info_all/2, info_all/4]). @@ -236,6 +236,20 @@ remove_default_exchange_binding_rows_of(Dst = #resource{}) -> end, ok. +-spec list_explicit() -> bindings(). + +list_explicit() -> + mnesia:async_dirty( + fun () -> + AllRoutes = mnesia:dirty_match_object(rabbit_route, #route{_ = '_'}), + %% if there are any default exchange bindings left after an upgrade + %% of a pre-3.8 database, filter them out + AllBindings = [B || #route{binding = B} <- AllRoutes], + lists:filter(fun(#binding{source = S}) -> + not (S#resource.kind =:= exchange andalso S#resource.name =:= <<>>) + end, AllBindings) + end). + -spec list(rabbit_types:vhost()) -> bindings(). list(VHostPath) -> diff --git a/src/rabbit_definitions.erl b/src/rabbit_definitions.erl index 47ac6a4992..ba2a17a45a 100644 --- a/src/rabbit_definitions.erl +++ b/src/rabbit_definitions.erl @@ -50,9 +50,8 @@ load_definitions(Body) -> all_definitions() -> Xs = list_exchanges(), Qs = list_queues(), -%% QNames = [{pget(name, Q), pget(vhost, Q)} || Q <- Qs], -%% Bs = [binding_definition(B) || B <- list_bindings()], -%% + Bs = list_bindings(), + Users = list_users(), VHosts = list_vhosts(), Params = list_runtime_parameters(), @@ -70,7 +69,7 @@ all_definitions() -> global_parameters => GParams, policies => Pols, queues => Qs, -%% bindings => Bs, + bindings => Bs, exchanges => Xs }. @@ -519,6 +518,22 @@ queue_definition(Q) -> <<"arguments">> => maps:from_list(Arguments) }. +list_bindings() -> + [binding_definition(B) || B <- rabbit_binding:list_explicit()]. + +binding_definition(#binding{source = S, + key = RoutingKey, + destination = D, + args = Args}) -> + Arguments = [{Key, Value} || {Key, _Type, Value} <- Args], + #{ + <<"source">> => S#resource.name, + <<"vhost">> => S#resource.virtual_host, + <<"destination">> => D#resource.name, + <<"destination_type">> => D#resource.kind, + <<"routing_key">> => RoutingKey, + <<"arguments">> => maps:from_list(Arguments) + }. list_vhosts() -> [vhost_definition(V) || V <- rabbit_vhost:all()]. |
