Skip to content

Commit

Permalink
Move code to declare to be called by all queue types.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonUnge committed May 9, 2024
1 parent e2b0e9b commit f011a8e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
16 changes: 0 additions & 16 deletions deps/rabbit/src/rabbit_channel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1065,21 +1065,6 @@ check_vhost_queue_limit(#resource{name = QueueName}, VHost) ->

end.

check_cluster_queue_limit(#resource{name = QueueName}) ->
case rabbit_misc:get_env(rabbit, cluster_queue_limit, infinity) of
infinity ->
false;
Limit ->
case rabbit_db_queue:count() >= Limit of
true ->
rabbit_misc:precondition_failed("cannot declare queue '~ts': "
"queue limit in cluster (~tp) is reached",
[QueueName, Limit]);
false ->
ok
end
end.

qbin_to_resource(QueueNameBin, VHostPath) ->
name_to_resource(queue, QueueNameBin, VHostPath).

Expand Down Expand Up @@ -2541,7 +2526,6 @@ handle_method(#'queue.declare'{queue = QueueNameBin,
{error, not_found} ->
%% enforce the limit for newly declared queues only
check_vhost_queue_limit(QueueName, VHostPath),
check_cluster_queue_limit(QueueName),
DlxKey = <<"x-dead-letter-exchange">>,
case rabbit_misc:r_arg(VHostPath, exchange, Args, DlxKey) of
undefined ->
Expand Down
17 changes: 17 additions & 0 deletions deps/rabbit/src/rabbit_queue_type.erl
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ is_compatible(Type, Durable, Exclusive, AutoDelete) ->
{'error', Err :: term() }.
declare(Q0, Node) ->
Q = rabbit_queue_decorator:set(rabbit_policy:set(Q0)),
ok = check_cluster_queue_limit(Q),
Mod = amqqueue:get_type(Q),
Mod:declare(Q, Node).

Expand Down Expand Up @@ -730,3 +731,19 @@ known_queue_type_names() ->
{QueueTypes, _} = lists:unzip(Registered),
QTypeBins = lists:map(fun(X) -> atom_to_binary(X) end, QueueTypes),
?KNOWN_QUEUE_TYPES ++ QTypeBins.

check_cluster_queue_limit(Q) ->
#resource{name = QueueName} = amqqueue:get_name(Q),
case rabbit_misc:get_env(rabbit, cluster_queue_limit, infinity) of
infinity ->
false;
Limit ->
case rabbit_db_queue:count() >= Limit of
true ->
rabbit_misc:precondition_failed("cannot declare queue '~ts': "
"queue limit in cluster (~tp) is reached",
[QueueName, Limit]);
false ->
ok
end
end.

0 comments on commit f011a8e

Please sign in to comment.