Skip to content

Commit

Permalink
HTTP API: DELETE /api/queues/{vhost}/{name} use internal API call
Browse files Browse the repository at this point in the history
A direct client operation fails if the queue is exclusive. This
API should behave like the rabbitmqctl that can delete the queue
even in that case
  • Loading branch information
dcorbacho committed Sep 27, 2023
1 parent 4eba619 commit 78f901a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
29 changes: 21 additions & 8 deletions deps/rabbitmq_management/src/rabbit_mgmt_wm_queue.erl
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,31 @@ accept_content(ReqData, Context) ->
rabbit_mgmt_util:bad_request(iolist_to_binary(io_lib:format(F ++ "~n", A)), ReqData, Context)
end.

delete_resource(ReqData, Context) ->
delete_resource(ReqData, Context = #context{user = #user{username = ActingUser}}) ->
%% We need to retrieve manually if-unused and if-empty, as the HTTP API uses '-'
%% while the record uses '_'
IfUnused = <<"true">> =:= rabbit_mgmt_util:qs_val(<<"if-unused">>, ReqData),
IfEmpty = <<"true">> =:= rabbit_mgmt_util:qs_val(<<"if-empty">>, ReqData),
Name = rabbit_mgmt_util:id(queue, ReqData),
rabbit_mgmt_util:direct_request(
'queue.delete',
fun rabbit_mgmt_format:format_accept_content/1,
[{queue, Name},
{if_unused, IfUnused},
{if_empty, IfEmpty}], "Delete queue error: ~ts", ReqData, Context).
VHost = rabbit_mgmt_util:id(vhost, ReqData),
QName = rabbit_mgmt_util:id(queue, ReqData),
Name = rabbit_misc:r(VHost, queue, QName),
case rabbit_amqqueue:lookup(Name) of
{ok, Q} ->
case rabbit_amqqueue:delete(Q, IfUnused, IfEmpty, ActingUser) of
{ok, _} ->
{true, ReqData, Context};
{error, not_empty} ->
Explanation = io_lib:format("~ts not empty", [rabbit_misc:rs(Name)]),
rabbit_log:warning("Delete queue error: ~ts", [Explanation]),
rabbit_mgmt_util:bad_request(list_to_binary(Explanation), ReqData, Context);
{error, in_use} ->
Explanation = io_lib:format("~ts in use", [rabbit_misc:rs(Name)]),
rabbit_log:warning("Delete queue error: ~ts", [Explanation]),
rabbit_mgmt_util:bad_request(list_to_binary(Explanation), ReqData, Context)
end;
{error, not_found} ->
{true, ReqData, Context}
end.

is_authorized(ReqData, Context) ->
rabbit_mgmt_util:is_authorized_vhost(ReqData, Context).
Expand Down
4 changes: 1 addition & 3 deletions deps/rabbitmq_management/test/rabbit_mgmt_http_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1993,9 +1993,7 @@ queue_purge_test(Config) ->
http_delete(Config, "/queues/%2F/myqueue/contents", {group, '2xx'}),
http_delete(Config, "/queues/%2F/badqueue/contents", ?NOT_FOUND),
http_delete(Config, "/queues/%2F/exclusive/contents", ?BAD_REQUEST),
http_delete(Config, "/queues/%2F/exclusive", ?BAD_REQUEST),
#'basic.get_empty'{} =
amqp_channel:call(Ch, #'basic.get'{queue = <<"myqueue">>}),
http_delete(Config, "/queues/%2F/exclusive", {group, '2xx'}),
close_channel(Ch),
close_connection(Conn),
http_delete(Config, "/queues/%2F/myqueue", {group, '2xx'}),
Expand Down

0 comments on commit 78f901a

Please # to comment.