Skip to content

Commit 2ea6120

Browse files
Merge pull request #15743 from rabbitmq/mc-ampq-modify-annotations
Optimise annotation expansion for mc_amqp
2 parents 2c142f4 + e550aeb commit 2ea6120

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

deps/rabbit/src/mc_amqp.erl

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -472,32 +472,46 @@ convert_from_3_13_msg(#msg{header = H,
472472

473473
-spec protocol_state_message_annotations(amqp_annotations(), mc:annotations()) ->
474474
amqp_annotations().
475-
protocol_state_message_annotations(MA, Anns) ->
475+
protocol_state_message_annotations(MA0, Anns) ->
476+
%% filter all MA's that are going to be overwritten by ANNS
477+
MA = lists:filter(
478+
fun
479+
({{symbol, <<"x-exchange">>}, _}) ->
480+
not maps:is_key(?ANN_EXCHANGE, Anns);
481+
({{symbol, <<"x-routing-key">>}, _}) ->
482+
not maps:is_key(?ANN_ROUTING_KEYS, Anns);
483+
({{symbol, <<"x-opt-rabbitmq-received-time">>}, _}) ->
484+
not maps:is_key(<<"timestamp_in_ms">>, Anns);
485+
({{symbol, <<"x-opt-deaths">>}, _}) ->
486+
not maps:is_key(deaths, Anns);
487+
({{symbol, <<"x-", _/binary>> = K}, _}) ->
488+
not maps:is_key(K, Anns);
489+
(_) ->
490+
true
491+
end, MA0),
492+
476493
maps:fold(
477494
fun(?ANN_EXCHANGE, Exchange, L) ->
478-
maps_upsert(<<"x-exchange">>, {utf8, Exchange}, L);
495+
[{{symbol, <<"x-exchange">>}, {utf8, Exchange}} | L];
479496
(?ANN_ROUTING_KEYS, RKeys, L) ->
480497
RKey = hd(RKeys),
481-
maps_upsert(<<"x-routing-key">>, {utf8, RKey}, L);
498+
[{{symbol, <<"x-routing-key">>}, {utf8, RKey}} | L];
482499
(<<"x-", _/binary>> = K, V, L)
483500
when V =/= undefined ->
484501
%% any x-* annotations get added as message annotations
485-
maps_upsert(K, mc_util:infer_type(V), L);
502+
[{{symbol, K}, mc_util:infer_type(V)} | L];
486503
(<<"timestamp_in_ms">>, V, L) ->
487-
maps_upsert(<<"x-opt-rabbitmq-received-time">>, {timestamp, V}, L);
504+
[{{symbol, <<"x-opt-rabbitmq-received-time">>},
505+
{timestamp, V}} | L];
488506
(deaths, Deaths, L)
489507
when is_list(Deaths) ->
490508
Maps = encode_deaths(Deaths),
491-
maps_upsert(<<"x-opt-deaths">>, {array, map, Maps}, L);
509+
[{{symbol, <<"x-opt-deaths">>},
510+
{array, map, Maps}} | L];
492511
(_, _, Acc) ->
493512
Acc
494513
end, MA, Anns).
495514

496-
maps_upsert(Key, TaggedVal, KVList) ->
497-
TaggedKey = {symbol, Key},
498-
Elem = {TaggedKey, TaggedVal},
499-
lists:keystore(TaggedKey, 1, KVList, Elem).
500-
501515
encode(Sections) when is_list(Sections) ->
502516
[amqp10_framing:encode_bin(Section) || Section <- Sections,
503517
not omit(Section)].

0 commit comments

Comments
 (0)