Skip to content

Commit a621859

Browse files
committed
Replace function references by MFAs
1 parent 5db4ae0 commit a621859

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

deps/rabbitmq_shovel/src/rabbit_amqp091_shovel.erl

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
%% from and can break with the next upgrade. It should not be used by
4040
%% another one that the one who created it or survive a node restart.
4141
%% Thus, function references have been replace by the following MFA.
42-
-export([decl_fun/3, publish_fun/4]).
42+
-export([decl_fun/3, publish_fun/4, props_fun_timestamp_header/4,
43+
props_fun_forward_header/5]).
4344

4445
-define(MAX_CONNECTION_CLOSE_TIMEOUT, 10000).
4546

@@ -559,23 +560,25 @@ field_map(Fields, Idx0) ->
559560
fail(Reason) -> throw({error, Reason}).
560561

561562
add_forward_headers_fun(Name, true, PubProps) ->
562-
fun(SrcUri, DestUri, Props) ->
563-
rabbit_shovel_util:update_headers(
564-
[{<<"shovelled-by">>, rabbit_nodes:cluster_name()},
565-
{<<"shovel-type">>, <<"static">>},
566-
{<<"shovel-name">>, list_to_binary(atom_to_list(Name))}],
567-
[], SrcUri, DestUri, PubProps(SrcUri, DestUri, Props))
568-
end;
563+
{?MODULE, props_fun_forward_header, [Name, PubProps]};
569564
add_forward_headers_fun(_Name, false, PubProps) ->
570565
PubProps.
571566

567+
props_fun_forward_header(Name, {M, F, Args}, SrcUri, DestUri, Props) ->
568+
rabbit_shovel_util:update_headers(
569+
[{<<"shovelled-by">>, rabbit_nodes:cluster_name()},
570+
{<<"shovel-type">>, <<"static">>},
571+
{<<"shovel-name">>, list_to_binary(atom_to_list(Name))}],
572+
[], SrcUri, DestUri, apply(M, F, Args ++ [SrcUri, DestUri, Props])).
573+
572574
add_timestamp_header_fun(true, PubProps) ->
573-
fun(SrcUri, DestUri, Props) ->
574-
rabbit_shovel_util:add_timestamp_header(
575-
PubProps(SrcUri, DestUri, Props))
576-
end;
575+
{?MODULE, props_fun_timestamp_header, [PubProps]};
577576
add_timestamp_header_fun(false, PubProps) -> PubProps.
578577

578+
props_fun_timestamp_header({M, F, Args}, SrcUri, DestUri, Props) ->
579+
rabbit_shovel_util:add_timestamp_header(
580+
apply(M, F, Args ++ [SrcUri, DestUri, Props])).
581+
579582
parse_declaration({[], Acc}) ->
580583
Acc;
581584
parse_declaration({[{Method, Props} | Rest], Acc}) when is_list(Props) ->

deps/rabbitmq_shovel/test/parameters_SUITE.erl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ test_parse_amqp091(Params) ->
159159
reconnect_delay := 1001,
160160
dest := #{module := rabbit_amqp091_shovel,
161161
uris := ["amqp://remotehost:5672"],
162-
props_fun := PropsFun
162+
props_fun := {M, F, Args}
163163
},
164164
source := #{module := rabbit_amqp091_shovel,
165165
uris := ["amqp://localhost:5672"],
@@ -170,9 +170,9 @@ test_parse_amqp091(Params) ->
170170

171171
#'P_basic'{headers = ActualHeaders,
172172
delivery_mode = 2,
173-
cluster_id = <<"x">>} = PropsFun("amqp://localhost:5672",
174-
"amqp://remotehost:5672",
175-
#'P_basic'{headers = undefined}),
173+
cluster_id = <<"x">>} = apply(M, F, Args ++ ["amqp://localhost:5672",
174+
"amqp://remotehost:5672",
175+
#'P_basic'{headers = undefined}]),
176176
assert_amqp901_headers(ActualHeaders),
177177
ok.
178178

@@ -185,7 +185,7 @@ test_parse_amqp091_with_blank_proprties(Params) ->
185185
reconnect_delay := 1001,
186186
dest := #{module := rabbit_amqp091_shovel,
187187
uris := ["amqp://remotehost:5672"],
188-
props_fun := PropsFun
188+
props_fun := {M, F, Args}
189189
},
190190
source := #{module := rabbit_amqp091_shovel,
191191
uris := ["amqp://localhost:5672"],
@@ -194,9 +194,9 @@ test_parse_amqp091_with_blank_proprties(Params) ->
194194
delete_after := 'queue-length'}
195195
} = Result,
196196

197-
#'P_basic'{headers = ActualHeaders} = PropsFun("amqp://localhost:5672",
198-
"amqp://remotehost:5672",
199-
#'P_basic'{headers = undefined}),
197+
#'P_basic'{headers = ActualHeaders} = apply(M, F, Args ++ ["amqp://localhost:5672",
198+
"amqp://remotehost:5672",
199+
#'P_basic'{headers = undefined}]),
200200
assert_amqp901_headers(ActualHeaders),
201201
ok.
202202

0 commit comments

Comments
 (0)