Skip to content

Commit 56af514

Browse files
committed
Return empty array when JMS topic exchange state does not exist
Instead of exiting. A few messages can get routed to a deleted exchange. The exchange has no state in Mnesia, so the previous code would return an error that would bubble up to the publisher and closing its channel. The exchange is created for a subscriber, so this would mean the deletion of a subscriber would impact a publisher. This commit makes the exchange return an empty array if no state is found. This is less drastic and hopefully more appropriate than returning an error. The exchange state should always be found under normal conditions. See #4616
1 parent 5a5fb2e commit 56af514

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

deps/rabbitmq_jms_topic_exchange/src/rabbit_jms_topic_exchange.erl

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,12 @@ serialise_events() -> false.
9999
route( #exchange{name = XName}
100100
, #delivery{message = #basic_message{content = MessageContent, routing_keys = RKs}}
101101
) ->
102-
BindingFuns = get_binding_funs_x(XName),
103-
match_bindings(XName, RKs, MessageContent, BindingFuns).
102+
case get_binding_funs_x(XName) of
103+
not_found ->
104+
[];
105+
BindingFuns ->
106+
match_bindings(XName, RKs, MessageContent, BindingFuns)
107+
end.
104108

105109

106110
% Before exchange declaration
@@ -232,8 +236,12 @@ selector_match(Selector, Headers) ->
232236
get_binding_funs_x(XName) ->
233237
mnesia:async_dirty(
234238
fun() ->
235-
#?JMS_TOPIC_RECORD{x_selector_funs = BindingFuns} = read_state(XName),
236-
BindingFuns
239+
case read_state_no_error(XName) of
240+
not_found ->
241+
not_found;
242+
#?JMS_TOPIC_RECORD{x_selector_funs = BindingFuns} ->
243+
BindingFuns
244+
end
237245
end,
238246
[]
239247
).
@@ -276,6 +284,14 @@ read_state(XName, Lock) ->
276284
_ -> exchange_state_corrupt_error(XName)
277285
end.
278286

287+
read_state_no_error(XName) ->
288+
case mnesia:read(?JMS_TOPIC_TABLE, XName, read) of
289+
[Rec] -> Rec;
290+
_ -> not_found
291+
end.
292+
293+
294+
279295
% Basic write
280296
write_state_fun(XName, BFuns) ->
281297
mnesia:write( ?JMS_TOPIC_TABLE

0 commit comments

Comments
 (0)