Skip to content

Commit f261041

Browse files
rabbit_exchange:lookup/1: support lists of keys
like rabbit_amqqueue does (cherry picked from commit 6eb7144)
1 parent 5ec6bbd commit f261041

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/rabbit_exchange.erl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@
5555
-spec assert_args_equivalence
5656
(rabbit_types:exchange(), rabbit_framing:amqp_table())
5757
-> 'ok' | rabbit_types:connection_exit().
58-
-spec lookup
59-
(name()) -> rabbit_types:ok(rabbit_types:exchange()) |
60-
rabbit_types:error('not_found').
6158
-spec lookup_or_die
6259
(name()) -> rabbit_types:exchange() |
6360
rabbit_types:channel_exit().
@@ -253,6 +250,18 @@ assert_args_equivalence(#exchange{ name = Name, arguments = Args },
253250
rabbit_misc:assert_args_equivalence(Args, RequiredArgs, Name,
254251
[<<"alternate-exchange">>]).
255252

253+
-spec lookup
254+
(name()) -> rabbit_types:ok(rabbit_types:exchange()) |
255+
rabbit_types:error('not_found');
256+
([name()]) ->
257+
[rabbit_types:exchange()].
258+
259+
lookup([]) -> [];
260+
lookup([Name]) -> ets:lookup(rabbit_exchange, Name);
261+
lookup(Names) when is_list(Names) ->
262+
%% Normally we'd call mnesia:dirty_read/1 here, but that is quite
263+
%% expensive for reasons explained in rabbit_misc:dirty_read/1.
264+
lists:append([ets:lookup(rabbit_exchange, Name) || Name <- Names]);
256265
lookup(Name) ->
257266
rabbit_misc:dirty_read({rabbit_exchange, Name}).
258267

0 commit comments

Comments
 (0)