Skip to content

Commit 49fdae9

Browse files
acogoluegnesansd
authored andcommitted
Support exchange unbind in AMQP management
1 parent 85c6b41 commit 49fdae9

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

deps/rabbit/src/rabbit_amqp_management.erl

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -224,25 +224,46 @@ process_http_request(<<"DELETE">>,
224224
end;
225225

226226
process_http_request(<<"DELETE">>,
227-
<<"/$management/exchanges/", XNameBin/binary>>,
227+
<<"/$management/exchanges/", Path/binary>>,
228228
undefined,
229229
[],
230230
Vhost,
231231
#user{username = Username},
232232
_ConnectionPid) ->
233-
XName = rabbit_misc:r(Vhost, exchange, XNameBin),
234-
ok = case rabbit_exchange:delete(XName, false, Username) of
235-
ok ->
236-
ok;
237-
{error, not_found} ->
238-
ok
239-
%% %% TODO return deletion failure
240-
%% {error, in_use} ->
241-
end,
242-
Props = #'v1_0.properties'{subject = {utf8, <<"204">>}},
243-
AppProps = #'v1_0.application_properties'{content = []},
244-
RespPayload = {map, []},
245-
{Props, AppProps, RespPayload};
233+
case re:split(Path, <<"/">>, [{return, binary}]) of
234+
[XNameBin] ->
235+
XName = rabbit_misc:r(Vhost, exchange, XNameBin),
236+
ok = case rabbit_exchange:delete(XName, false, Username) of
237+
ok ->
238+
ok;
239+
{error, not_found} ->
240+
ok
241+
%% %% TODO return deletion failure
242+
%% {error, in_use} ->
243+
end,
244+
Props = #'v1_0.properties'{subject = {utf8, <<"204">>}},
245+
AppProps = #'v1_0.application_properties'{content = []},
246+
RespPayload = {map, []},
247+
{Props, AppProps, RespPayload};
248+
[XNameBin, <<"bindings">>, SrcXNameBin, BindingKey, ArgsHash] ->
249+
SrcXName = rabbit_misc:r(Vhost, exchange, SrcXNameBin),
250+
XName = rabbit_misc:r(Vhost, exchange, XNameBin),
251+
Bindings0 = rabbit_binding:list_for_source_and_destination(SrcXName, XName, true),
252+
case lists:search(fun(#binding{key = Key,
253+
args = Args}) ->
254+
Key =:= BindingKey andalso
255+
args_hash(Args) =:= ArgsHash
256+
end, Bindings0) of
257+
{value, Binding} ->
258+
ok = rabbit_binding:remove(Binding, Username);
259+
false ->
260+
ok
261+
end,
262+
Props = #'v1_0.properties'{subject = {utf8, <<"204">>}},
263+
AppProps = #'v1_0.application_properties'{content = []},
264+
RespPayload = {map, []},
265+
{Props, AppProps, RespPayload}
266+
end;
246267

247268
process_http_request(<<"GET">>,
248269
<<"/$management/", Path0/binary>>,

0 commit comments

Comments
 (0)