Skip to content

Commit 21cb004

Browse files
committed
Make plugin compatible with 3.12
due to rabbitmq/rabbitmq-server#682
1 parent dfffdee commit 21cb004

File tree

2 files changed

+45
-28
lines changed

2 files changed

+45
-28
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ basic_publish(Msg, "rtopic", "server1.app1.#").
4949

5050
The exchange type used when declaring an exchange is `x-rtopic`.
5151

52+
## Supported RabbitMQ Versions
53+
54+
The most recent release of this plugin targets RabbitMQ 3.12.x.
55+
56+
## Supported Erlang/OTP Versions
57+
58+
This plugin [requires Erlang 25.0 or later versions](https://www.rabbitmq.com/which-erlang.html), same as RabbitMQ 3.12.x.
59+
5260
## Installation and Binary Builds
5361

5462
This plugin is now available from the [RabbitMQ community plugins page](https://www.rabbitmq.com/community-plugins.html).

src/rabbit_exchange_type_rtopic.erl

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
-export([description/0, serialise_events/0, route/2]).
2020
-export([validate/1, validate_binding/2,
21-
create/2, delete/3, policy_changed/2, add_binding/3,
21+
create/2, delete/2, policy_changed/2, add_binding/3,
2222
remove_bindings/3, assert_args_equivalence/2]).
2323
-export([init/0]).
2424
-export([info/1, info/2]).
@@ -67,41 +67,50 @@ route(#exchange{name = X},
6767

6868
validate(_X) -> ok.
6969
validate_binding(_X, _B) -> ok.
70-
create(_Tx, _X) -> ok.
71-
72-
delete(transaction, #exchange{name = X}, _Bs) ->
73-
trie_remove_all_nodes(X),
74-
trie_remove_all_edges(X),
75-
trie_remove_all_bindings(X),
70+
create(_Serial, _X) -> ok.
71+
72+
delete(none, #exchange{name = X}) ->
73+
rabbit_mnesia:execute_mnesia_transaction(
74+
fun() ->
75+
trie_remove_all_nodes(X),
76+
trie_remove_all_edges(X),
77+
trie_remove_all_bindings(X)
78+
end),
7679
ok;
77-
delete(none, _Exchange, _Bs) ->
80+
delete(_Serial, _X) ->
7881
ok.
7982

8083
policy_changed(_X1, _X2) -> ok.
8184

82-
add_binding(transaction, _Exchange, Binding) ->
83-
internal_add_binding(Binding);
84-
add_binding(none, _Exchange, _Binding) ->
85+
add_binding(none, _Exchange, Binding) ->
86+
rabbit_mnesia:execute_mnesia_transaction(
87+
fun() ->
88+
internal_add_binding(Binding)
89+
end);
90+
add_binding(_Serial, _Exchange, _Binding) ->
8591
ok.
8692

87-
remove_bindings(transaction, _X, Bs) ->
88-
%% See rabbit_binding:lock_route_tables for the rationale for
89-
%% taking table locks.
90-
_ = case Bs of
91-
[_] -> ok;
92-
_ -> [mnesia:lock({table, T}, write) ||
93-
T <- [rabbit_rtopic_trie_node,
94-
rabbit_rtopic_trie_edge,
95-
rabbit_rtopic_trie_binding]]
96-
end,
97-
[begin
98-
Path = [{FinalNode, _} | _] =
99-
follow_down_get_path(X, split_topic_key(K)),
100-
trie_remove_binding(X, FinalNode, D),
101-
remove_path_if_empty(X, Path)
102-
end || #binding{source = X, key = K, destination = D} <- Bs],
93+
remove_bindings(none, _X, Bs) ->
94+
rabbit_mnesia:execute_mnesia_transaction(
95+
fun() ->
96+
%% See rabbit_binding:lock_route_tables for the rationale for
97+
%% taking table locks.
98+
_ = case Bs of
99+
[_] -> ok;
100+
_ -> [mnesia:lock({table, T}, write) ||
101+
T <- [rabbit_rtopic_trie_node,
102+
rabbit_rtopic_trie_edge,
103+
rabbit_rtopic_trie_binding]]
104+
end,
105+
[begin
106+
Path = [{FinalNode, _} | _] =
107+
follow_down_get_path(X, split_topic_key(K)),
108+
trie_remove_binding(X, FinalNode, D),
109+
remove_path_if_empty(X, Path)
110+
end || #binding{source = X, key = K, destination = D} <- Bs]
111+
end),
103112
ok;
104-
remove_bindings(none, _X, _Bs) ->
113+
remove_bindings(_Serial, _X, _Bs) ->
105114
ok.
106115

107116
assert_args_equivalence(X, Args) ->

0 commit comments

Comments
 (0)