Skip to content

Commit b89befc

Browse files
committed
cluster wide queue limit
1 parent e2b0e9b commit b89befc

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

deps/rabbit/src/rabbit_amqqueue.erl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ declare(QueueName, Durable, AutoDelete, Args, Owner, ActingUser) ->
223223
declare(QueueName = #resource{virtual_host = VHost}, Durable, AutoDelete, Args,
224224
Owner, ActingUser, Node) ->
225225
ok = check_declare_arguments(QueueName, Args),
226+
ok = check_cluster_queue_limit(QueueName),
226227
Type = get_queue_type(Args),
227228
case rabbit_queue_type:is_enabled(Type) of
228229
true ->
@@ -1122,6 +1123,21 @@ check_queue_type(Val, _Args) when is_binary(Val) ->
11221123
check_queue_type(_Val, _Args) ->
11231124
{error, invalid_queue_type}.
11241125

1126+
check_cluster_queue_limit(#resource{name = QueueName}) ->
1127+
case rabbit_misc:get_env(rabbit, cluster_queue_limit, infinity) of
1128+
infinity ->
1129+
false;
1130+
Limit ->
1131+
case rabbit_db_queue:count() >= Limit of
1132+
true ->
1133+
rabbit_misc:precondition_failed("cannot declare queue '~ts': "
1134+
"queue limit in cluster (~tp) is reached",
1135+
[QueueName, Limit]);
1136+
false ->
1137+
ok
1138+
end
1139+
end.
1140+
11251141
-spec list() -> [amqqueue:amqqueue()].
11261142

11271143
list() ->

deps/rabbit/src/rabbit_channel.erl

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,21 +1065,6 @@ check_vhost_queue_limit(#resource{name = QueueName}, VHost) ->
10651065

10661066
end.
10671067

1068-
check_cluster_queue_limit(#resource{name = QueueName}) ->
1069-
case rabbit_misc:get_env(rabbit, cluster_queue_limit, infinity) of
1070-
infinity ->
1071-
false;
1072-
Limit ->
1073-
case rabbit_db_queue:count() >= Limit of
1074-
true ->
1075-
rabbit_misc:precondition_failed("cannot declare queue '~ts': "
1076-
"queue limit in cluster (~tp) is reached",
1077-
[QueueName, Limit]);
1078-
false ->
1079-
ok
1080-
end
1081-
end.
1082-
10831068
qbin_to_resource(QueueNameBin, VHostPath) ->
10841069
name_to_resource(queue, QueueNameBin, VHostPath).
10851070

@@ -2541,7 +2526,6 @@ handle_method(#'queue.declare'{queue = QueueNameBin,
25412526
{error, not_found} ->
25422527
%% enforce the limit for newly declared queues only
25432528
check_vhost_queue_limit(QueueName, VHostPath),
2544-
check_cluster_queue_limit(QueueName),
25452529
DlxKey = <<"x-dead-letter-exchange">>,
25462530
case rabbit_misc:r_arg(VHostPath, exchange, Args, DlxKey) of
25472531
undefined ->

0 commit comments

Comments
 (0)