Skip to content

Commit 3c9cfe4

Browse files
Merge pull request #14280 from cloudamqp/cq_info
Classic queues: return basic info items without calling queue process
2 parents 84e0478 + 21556b5 commit 3c9cfe4

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

deps/rabbit/src/rabbit_classic_queue.erl

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@
1919
monitored = #{} :: #{pid() => ok}
2020
}).
2121

22+
-define(STATIC_KEYS, [name,
23+
durable,
24+
auto_delete,
25+
arguments,
26+
pid,
27+
leader,
28+
members,
29+
owner_pid,
30+
exclusive,
31+
policy,
32+
operator_policy,
33+
effective_policy_definition,
34+
type]).
2235

2336
-opaque state() :: #?STATE{}.
2437

@@ -510,6 +523,16 @@ state_info(_State) ->
510523
-spec info(amqqueue:amqqueue(), all_keys | rabbit_types:info_keys()) ->
511524
rabbit_types:infos().
512525
info(Q, Items) ->
526+
AllStaticItems = is_list(Items) andalso
527+
lists:all(fun(I) -> lists:member(I, ?STATIC_KEYS) end, Items),
528+
case AllStaticItems of
529+
true ->
530+
static_info(Q, Items);
531+
false ->
532+
info_call(Q, Items)
533+
end.
534+
535+
info_call(Q, Items) ->
513536
QPid = amqqueue:get_pid(Q),
514537
Req = case Items of
515538
all_keys -> info;
@@ -525,6 +548,48 @@ info(Q, Items) ->
525548
Result
526549
end.
527550

551+
static_info(Q, Items) ->
552+
[{I, i(I, Q)} || I <- Items].
553+
554+
i(name, Q) ->
555+
amqqueue:get_name(Q);
556+
i(durable, Q) ->
557+
amqqueue:is_durable(Q);
558+
i(auto_delete, Q) ->
559+
amqqueue:is_auto_delete(Q);
560+
i(arguments, Q) ->
561+
amqqueue:get_arguments(Q);
562+
i(pid, Q) ->
563+
amqqueue:get_pid(Q);
564+
i(leader, Q) ->
565+
node(i(pid, Q));
566+
i(members, Q) ->
567+
[i(leader, Q)];
568+
i(owner_pid, Q) when ?amqqueue_exclusive_owner_is(Q, none) ->
569+
'';
570+
i(owner_pid, Q) ->
571+
amqqueue:get_exclusive_owner(Q);
572+
i(exclusive, Q) ->
573+
ExclusiveOwner = amqqueue:get_exclusive_owner(Q),
574+
is_pid(ExclusiveOwner);
575+
i(policy, Q) ->
576+
case rabbit_policy:name(Q) of
577+
none -> '';
578+
Policy -> Policy
579+
end;
580+
i(operator_policy, Q) ->
581+
case rabbit_policy:name_op(Q) of
582+
none -> '';
583+
Policy -> Policy
584+
end;
585+
i(effective_policy_definition, Q) ->
586+
case rabbit_policy:effective_definition(Q) of
587+
undefined -> [];
588+
Def -> Def
589+
end;
590+
i(type, _) ->
591+
classic.
592+
528593
-spec purge(amqqueue:amqqueue()) ->
529594
{ok, non_neg_integer()}.
530595
purge(Q) when ?is_amqqueue(Q) ->

0 commit comments

Comments
 (0)