Skip to content

Commit f124bca

Browse files
Merge pull request #11222 from SimonUnge/move_vhost_limit_check
Enforce/honor per-vhost queue limit for all protocols
2 parents 6047583 + 4a6c009 commit f124bca

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
@@ -1013,15 +1013,6 @@ check_msg_size(Content, GCThreshold) ->
10131013
Fmt, [Size, MaxMessageSize])
10141014
end.
10151015

1016-
check_vhost_queue_limit(#resource{name = QueueName}, VHost) ->
1017-
case rabbit_vhost_limit:is_over_queue_limit(VHost) of
1018-
false -> ok;
1019-
{true, Limit} -> rabbit_misc:precondition_failed("cannot declare queue '~ts': "
1020-
"queue limit in vhost '~ts' (~tp) is reached",
1021-
[QueueName, VHost, Limit])
1022-
1023-
end.
1024-
10251016
qbin_to_resource(QueueNameBin, VHostPath) ->
10261017
name_to_resource(queue, QueueNameBin, VHostPath).
10271018

@@ -2471,7 +2462,6 @@ handle_method(#'queue.declare'{queue = QueueNameBin,
24712462
{ok, QueueName, MessageCount, ConsumerCount};
24722463
{error, not_found} ->
24732464
%% enforce the limit for newly declared queues only
2474-
check_vhost_queue_limit(QueueName, VHostPath),
24752465
DlxKey = <<"x-dead-letter-exchange">>,
24762466
case rabbit_misc:r_arg(VHostPath, exchange, Args, DlxKey) of
24772467
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

@@ -307,7 +308,12 @@ is_compatible(Type, Durable, Exclusive, AutoDelete) ->
307308
declare(Q0, Node) ->
308309
Q = rabbit_queue_decorator:set(rabbit_policy:set(Q0)),
309310
Mod = amqqueue:get_type(Q),
310-
Mod:declare(Q, Node).
311+
case check_queue_limits(Q) of
312+
ok ->
313+
Mod:declare(Q, Node);
314+
Error ->
315+
Error
316+
end.
311317

312318
-spec delete(amqqueue:amqqueue(), boolean(),
313319
boolean(), rabbit_types:username()) ->
@@ -765,3 +771,25 @@ known_queue_type_names() ->
765771
{QueueTypes, _} = lists:unzip(Registered),
766772
QTypeBins = lists:map(fun(X) -> atom_to_binary(X) end, QueueTypes),
767773
?KNOWN_QUEUE_TYPES ++ QTypeBins.
774+
775+
-spec check_queue_limits(amqqueue:amqqueue()) ->
776+
ok |
777+
{protocol_error, Type :: atom(), Reason :: string(), Args :: term()}.
778+
check_queue_limits(Q) ->
779+
maybe
780+
%% Prepare for more checks
781+
ok ?= check_vhost_queue_limit(Q)
782+
end.
783+
784+
check_vhost_queue_limit(Q) ->
785+
#resource{name = QueueName} = amqqueue:get_name(Q),
786+
VHost = amqqueue:get_vhost(Q),
787+
case rabbit_vhost_limit:is_over_queue_limit(VHost) of
788+
false ->
789+
ok;
790+
{true, Limit} ->
791+
{protocol_error, precondition_failed,
792+
"cannot declare queue '~ts': "
793+
"queue limit in vhost '~ts' (~tp) is reached",
794+
[QueueName, VHost, Limit]}
795+
end.

0 commit comments

Comments
 (0)