Skip to content

Commit 3b986c3

Browse files
Merge pull request #11293 from rabbitmq/mergify/bp/v3.13.x/pr-11222
Enforce/honor per-vhost queue limit for all protocols (backport #11222)
2 parents 6dbe4de + f97bc42 commit 3b986c3

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

deps/rabbit/src/rabbit_channel.erl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,15 +1056,6 @@ check_msg_size(Content, MaxMessageSize, GCThreshold) ->
10561056
_ -> ok
10571057
end.
10581058

1059-
check_vhost_queue_limit(#resource{name = QueueName}, VHost) ->
1060-
case rabbit_vhost_limit:is_over_queue_limit(VHost) of
1061-
false -> ok;
1062-
{true, Limit} -> rabbit_misc:precondition_failed("cannot declare queue '~ts': "
1063-
"queue limit in vhost '~ts' (~tp) is reached",
1064-
[QueueName, VHost, Limit])
1065-
1066-
end.
1067-
10681059
qbin_to_resource(QueueNameBin, VHostPath) ->
10691060
name_to_resource(queue, QueueNameBin, VHostPath).
10701061

@@ -2525,7 +2516,6 @@ handle_method(#'queue.declare'{queue = QueueNameBin,
25252516
{ok, QueueName, MessageCount, ConsumerCount};
25262517
{error, not_found} ->
25272518
%% enforce the limit for newly declared queues only
2528-
check_vhost_queue_limit(QueueName, VHostPath),
25292519
DlxKey = <<"x-dead-letter-exchange">>,
25302520
case rabbit_misc:r_arg(VHostPath, exchange, Args, DlxKey) of
25312521
undefined ->

deps/rabbit/src/rabbit_queue_type.erl

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
%%
77

88
-module(rabbit_queue_type).
9+
-feature(maybe_expr, enable).
910

1011
-behaviour(rabbit_registry_class).
1112

@@ -282,7 +283,12 @@ is_compatible(Type, Durable, Exclusive, AutoDelete) ->
282283
declare(Q0, Node) ->
283284
Q = rabbit_queue_decorator:set(rabbit_policy:set(Q0)),
284285
Mod = amqqueue:get_type(Q),
285-
Mod:declare(Q, Node).
286+
case check_queue_limits(Q) of
287+
ok ->
288+
Mod:declare(Q, Node);
289+
Error ->
290+
Error
291+
end.
286292

287293
-spec delete(amqqueue:amqqueue(), boolean(),
288294
boolean(), rabbit_types:username()) ->
@@ -730,3 +736,25 @@ known_queue_type_names() ->
730736
{QueueTypes, _} = lists:unzip(Registered),
731737
QTypeBins = lists:map(fun(X) -> atom_to_binary(X) end, QueueTypes),
732738
?KNOWN_QUEUE_TYPES ++ QTypeBins.
739+
740+
-spec check_queue_limits(amqqueue:amqqueue()) ->
741+
ok |
742+
{protocol_error, Type :: atom(), Reason :: string(), Args :: term()}.
743+
check_queue_limits(Q) ->
744+
maybe
745+
%% Prepare for more checks
746+
ok ?= check_vhost_queue_limit(Q)
747+
end.
748+
749+
check_vhost_queue_limit(Q) ->
750+
#resource{name = QueueName} = amqqueue:get_name(Q),
751+
VHost = amqqueue:get_vhost(Q),
752+
case rabbit_vhost_limit:is_over_queue_limit(VHost) of
753+
false ->
754+
ok;
755+
{true, Limit} ->
756+
{protocol_error, precondition_failed,
757+
"cannot declare queue '~ts': "
758+
"queue limit in vhost '~ts' (~tp) is reached",
759+
[QueueName, VHost, Limit]}
760+
end.

0 commit comments

Comments
 (0)