Skip to content

Commit 7975881

Browse files
Merge pull request #4696 from rabbitmq/rabbitmq-jms-topic-exchange-return-empty-array-when-no-state
Return empty array when JMS topic exchange state does not exist
2 parents 5a5fb2e + 217736a commit 7975881

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

deps/rabbitmq_jms_topic_exchange/src/rabbit_jms_topic_exchange.erl

Lines changed: 20 additions & 7 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
).
@@ -266,16 +274,21 @@ delete_state(XName) ->
266274
% Basic read for update
267275
read_state_for_update(XName) -> read_state(XName, write).
268276

269-
% Basic read
270-
read_state(XName) -> read_state(XName, read).
271-
272277
% Lockable read
273278
read_state(XName, Lock) ->
274279
case mnesia:read(?JMS_TOPIC_TABLE, XName, Lock) of
275280
[Rec] -> Rec;
276281
_ -> exchange_state_corrupt_error(XName)
277282
end.
278283

284+
read_state_no_error(XName) ->
285+
case mnesia:read(?JMS_TOPIC_TABLE, XName, read) of
286+
[Rec] -> Rec;
287+
_ -> not_found
288+
end.
289+
290+
291+
279292
% Basic write
280293
write_state_fun(XName, BFuns) ->
281294
mnesia:write( ?JMS_TOPIC_TABLE

0 commit comments

Comments
 (0)