Skip to content

Commit 24e90d5

Browse files
Merge pull request #2032 from rabbitmq/v3.7.x-backport-amqqueue-api
Backport the `amqqueue` API to RabbitMQ 3.7.x
2 parents 8c4d0ef + bff7ef1 commit 24e90d5

File tree

4 files changed

+842
-0
lines changed

4 files changed

+842
-0
lines changed

include/amqqueue.hrl

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
%% The contents of this file are subject to the Mozilla Public License
2+
%% Version 1.1 (the "License"); you may not use this file except in
3+
%% compliance with the License. You may obtain a copy of the License
4+
%% at https://www.mozilla.org/MPL/
5+
%%
6+
%% Software distributed under the License is distributed on an "AS IS"
7+
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
8+
%% the License for the specific language governing rights and
9+
%% limitations under the License.
10+
%%
11+
%% The Original Code is RabbitMQ.
12+
%%
13+
%% The Initial Developer of the Original Code is GoPivotal, Inc.
14+
%% Copyright (c) 2018-2019 Pivotal Software, Inc. All rights reserved.
15+
%%
16+
17+
-include("amqqueue_v1.hrl").
18+
19+
-define(is_amqqueue(Q),
20+
(?is_amqqueue_v1(Q))).
21+
22+
-define(amqqueue_is_auto_delete(Q),
23+
((?is_amqqueue_v1(Q) andalso
24+
?amqqueue_v1_field_auto_delete(Q) =:= true))).
25+
26+
-define(amqqueue_is_durable(Q),
27+
((?is_amqqueue_v1(Q) andalso
28+
?amqqueue_v1_field_durable(Q) =:= true))).
29+
30+
-define(amqqueue_exclusive_owner_is(Q, Owner),
31+
((?is_amqqueue_v1(Q) andalso
32+
?amqqueue_v1_field_exclusive_owner(Q) =:= Owner))).
33+
34+
-define(amqqueue_exclusive_owner_is_pid(Q),
35+
((?is_amqqueue_v1(Q) andalso
36+
is_pid(?amqqueue_v1_field_exclusive_owner(Q))))).
37+
38+
-define(amqqueue_state_is(Q, State),
39+
((?is_amqqueue_v1(Q) andalso
40+
?amqqueue_v1_field_state(Q) =:= State))).
41+
42+
-define(amqqueue_v1_type, classic).
43+
44+
-define(amqqueue_is_classic(Q),
45+
(?is_amqqueue_v1(Q))).
46+
47+
-define(amqqueue_is_quorum(Q),
48+
false).
49+
50+
-define(amqqueue_has_valid_pid(Q),
51+
(?is_amqqueue_v1(Q) andalso
52+
is_pid(?amqqueue_v1_field_pid(Q)))).
53+
54+
-define(amqqueue_pid_runs_on_local_node(Q),
55+
(?is_amqqueue_v1(Q) andalso
56+
node(?amqqueue_v1_field_pid(Q)) =:= node())).
57+
58+
-define(amqqueue_pid_equals(Q, Pid),
59+
((?is_amqqueue_v1(Q) andalso
60+
?amqqueue_v1_field_pid(Q) =:= Pid))).
61+
62+
-define(amqqueue_pids_are_equal(Q0, Q1),
63+
((?is_amqqueue_v1(Q0) andalso ?is_amqqueue_v1(Q1) andalso
64+
?amqqueue_v1_field_pid(Q0) =:= ?amqqueue_v1_field_pid(Q1)))).
65+
66+
-define(amqqueue_field_name(Q),
67+
case ?is_amqqueue_v1(Q) of
68+
true -> ?amqqueue_v1_field_name(Q)
69+
end).
70+
71+
-define(amqqueue_field_pid(Q),
72+
case ?is_amqqueue_v1(Q) of
73+
true -> ?amqqueue_v1_field_pid(Q)
74+
end).
75+
76+
-define(amqqueue_v1_vhost(Q), element(2, ?amqqueue_v1_field_name(Q))).
77+
78+
-define(amqqueue_vhost_equals(Q, VHost),
79+
((?is_amqqueue_v1(Q) andalso
80+
?amqqueue_v1_vhost(Q) =:= VHost))).
81+
82+
-define(enable_quorum_queue_if_debug, noop).
83+
84+
-define(try_mnesia_tx_or_upgrade_amqqueue_and_retry(Expr1, Expr2),
85+
try
86+
?enable_quorum_queue_if_debug,
87+
Expr1
88+
catch
89+
throw:{error, {bad_type, T}} when ?is_amqqueue(T) ->
90+
Expr2;
91+
throw:{aborted, {bad_type, T}} when ?is_amqqueue(T) ->
92+
Expr2
93+
end).

include/amqqueue_v1.hrl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-define(is_amqqueue_v1(Q), is_record(Q, amqqueue, 19)).
2+
3+
-define(amqqueue_v1_field_name(Q), element(2, Q)).
4+
-define(amqqueue_v1_field_durable(Q), element(3, Q)).
5+
-define(amqqueue_v1_field_auto_delete(Q), element(4, Q)).
6+
-define(amqqueue_v1_field_exclusive_owner(Q), element(5, Q)).
7+
-define(amqqueue_v1_field_arguments(Q), element(6, Q)).
8+
-define(amqqueue_v1_field_pid(Q), element(7, Q)).
9+
-define(amqqueue_v1_field_slave_pids(Q), element(8, Q)).
10+
-define(amqqueue_v1_field_sync_slave_pids(Q), element(9, Q)).
11+
-define(amqqueue_v1_field_recoverable_slaves(Q), element(10, Q)).
12+
-define(amqqueue_v1_field_policy(Q), element(11, Q)).
13+
-define(amqqueue_v1_field_operator_policy(Q), element(12, Q)).
14+
-define(amqqueue_v1_field_gm_pids(Q), element(13, Q)).
15+
-define(amqqueue_v1_field_decorators(Q), element(14, Q)).
16+
-define(amqqueue_v1_field_state(Q), element(15, Q)).
17+
-define(amqqueue_v1_field_policy_version(Q), element(16, Q)).
18+
-define(amqqueue_v1_field_slave_pids_pending_shutdown(Q), element(17, Q)).
19+
-define(amqqueue_v1_field_vhost(Q), element(18, Q)).
20+
-define(amqqueue_v1_field_options(Q), element(19, Q)).

0 commit comments

Comments
 (0)