Skip to content

Commit 4a3a954

Browse files
authored
Merge pull request #11232 from rabbitmq/mergify/bp/v3.13.x/pr-11230
Remove BCC from x-death routing-keys (backport #11230)
2 parents cd079d9 + f8ddfe6 commit 4a3a954

File tree

3 files changed

+47
-16
lines changed

3 files changed

+47
-16
lines changed

deps/rabbit/src/mc.erl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,14 +348,22 @@ record_death(Reason, SourceQueue,
348348
is_binary(SourceQueue) ->
349349
Key = {SourceQueue, Reason},
350350
#{?ANN_EXCHANGE := Exchange,
351-
?ANN_ROUTING_KEYS := RoutingKeys} = Anns0,
351+
?ANN_ROUTING_KEYS := RKeys0} = Anns0,
352+
%% The routing keys that we record in the death history and will
353+
%% report to the client should include CC, but exclude BCC.
354+
RKeys = case Anns0 of
355+
#{bcc := BccKeys} ->
356+
RKeys0 -- BccKeys;
357+
_ ->
358+
RKeys0
359+
end,
352360
Timestamp = os:system_time(millisecond),
353361
Ttl = maps:get(ttl, Anns0, undefined),
354362
DeathAnns = rabbit_misc:maps_put_truthy(
355363
ttl, Ttl, #{first_time => Timestamp,
356364
last_time => Timestamp}),
357365
NewDeath = #death{exchange = Exchange,
358-
routing_keys = RoutingKeys,
366+
routing_keys = RKeys,
359367
count = 1,
360368
anns = DeathAnns},
361369
Anns = case Anns0 of

deps/rabbit/src/mc_amqpl.erl

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@
4949

5050
%% mc implementation
5151
init(#content{} = Content0) ->
52-
Content = rabbit_binary_parser:ensure_content_decoded(Content0),
52+
Content1 = rabbit_binary_parser:ensure_content_decoded(Content0),
5353
%% project essential properties into annotations
54-
Anns = essential_properties(Content),
55-
{strip_header(Content, ?DELETED_HEADER), Anns}.
54+
Anns = essential_properties(Content1),
55+
Content = strip_header(Content1, ?DELETED_HEADER),
56+
{Content, Anns}.
5657

5758
convert_from(mc_amqp, Sections, _Env) ->
5859
{H, MAnn, Prop, AProp, BodyRev} =
@@ -480,7 +481,7 @@ message(#resource{name = ExchangeNameBin}, RoutingKey,
480481
Error;
481482
HeaderRoutes ->
482483
{ok, mc:init(?MODULE,
483-
rabbit_basic:strip_bcc_header(Content),
484+
Content,
484485
Anns#{?ANN_ROUTING_KEYS => [RoutingKey | HeaderRoutes],
485486
?ANN_EXCHANGE => ExchangeNameBin})}
486487
end;
@@ -734,7 +735,8 @@ message_id(undefined, _HKey, H) ->
734735
essential_properties(#content{} = C) ->
735736
#'P_basic'{delivery_mode = Mode,
736737
priority = Priority,
737-
timestamp = TimestampRaw} = Props = C#content.properties,
738+
timestamp = TimestampRaw,
739+
headers = Headers} = Props = C#content.properties,
738740
{ok, MsgTTL} = rabbit_basic:parse_expiration(Props),
739741
Timestamp = case TimestampRaw of
740742
undefined ->
@@ -744,6 +746,12 @@ essential_properties(#content{} = C) ->
744746
TimestampRaw * 1000
745747
end,
746748
Durable = Mode == 2,
749+
BccKeys = case rabbit_basic:header(<<"BCC">>, Headers) of
750+
{<<"BCC">>, array, Routes} ->
751+
[Route || {longstr, Route} <- Routes];
752+
_ ->
753+
undefined
754+
end,
747755
maps_put_truthy(
748756
?ANN_PRIORITY, Priority,
749757
maps_put_truthy(
@@ -752,7 +760,9 @@ essential_properties(#content{} = C) ->
752760
?ANN_TIMESTAMP, Timestamp,
753761
maps_put_falsy(
754762
?ANN_DURABLE, Durable,
755-
#{})))).
763+
maps_put_truthy(
764+
bcc, BccKeys,
765+
#{}))))).
756766

757767
%% headers that are added as annotations during conversions
758768
is_internal_header(<<"x-basic-", _/binary>>) ->

deps/rabbit/test/dead_lettering_SUITE.erl

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,17 +1391,18 @@ dead_letter_headers_BCC(Config) ->
13911391
routing_key = DLXQName}),
13921392

13931393
P1 = <<"msg1">>,
1394-
BCCHeader = {<<"BCC">>, array, [{longstr, DLXQName}]},
1395-
publish(Ch, QName, [P1], [BCCHeader]),
1394+
CCHeader = {<<"CC">>, array, [{longstr, <<"cc 1">>}, {longstr, <<"cc 2">>}]},
1395+
BCCHeader = {<<"BCC">>, array, [{longstr, DLXQName}, {longstr, <<"bcc 2">>}]},
1396+
publish(Ch, QName, [P1], [CCHeader, BCCHeader]),
13961397
%% Message is published to both queues because of BCC header and DLX queue bound to both
13971398
%% exchanges
13981399
wait_for_messages(Config, [[QName, <<"1">>, <<"1">>, <<"0">>]]),
13991400
{#'basic.get_ok'{delivery_tag = DTag1}, #amqp_msg{payload = P1,
14001401
props = #'P_basic'{headers = Headers1}}} =
1401-
amqp_channel:call(Ch, #'basic.get'{queue = QName}),
1402+
amqp_channel:call(Ch, #'basic.get'{queue = QName}),
14021403
{#'basic.get_ok'{}, #amqp_msg{payload = P1,
14031404
props = #'P_basic'{headers = Headers2}}} =
1404-
amqp_channel:call(Ch, #'basic.get'{queue = DLXQName}),
1405+
amqp_channel:call(Ch, #'basic.get'{queue = DLXQName}),
14051406
%% We check the headers to ensure no dead lettering has happened
14061407
?assertEqual(undefined, header_lookup(Headers1, <<"x-death">>)),
14071408
?assertEqual(undefined, header_lookup(Headers2, <<"x-death">>)),
@@ -1413,10 +1414,15 @@ dead_letter_headers_BCC(Config) ->
14131414
wait_for_messages(Config, [[DLXQName, <<"2">>, <<"1">>, <<"1">>]]),
14141415
{#'basic.get_ok'{}, #amqp_msg{payload = P1,
14151416
props = #'P_basic'{headers = Headers3}}} =
1416-
amqp_channel:call(Ch, #'basic.get'{queue = DLXQName}),
1417+
amqp_channel:call(Ch, #'basic.get'{queue = DLXQName}),
14171418
consume_empty(Ch, QName),
14181419
?assertEqual(undefined, rabbit_misc:table_lookup(Headers3, <<"BCC">>)),
1419-
?assertMatch({array, _}, rabbit_misc:table_lookup(Headers3, <<"x-death">>)).
1420+
{array, [{table, Death}]} = rabbit_misc:table_lookup(Headers3, <<"x-death">>),
1421+
{array, RKeys0} = rabbit_misc:table_lookup(Death, <<"routing-keys">>),
1422+
RKeys = [RKey || {longstr, RKey} <- RKeys0],
1423+
%% routing-keys in the death history should include CC but exclude BCC keys
1424+
?assertEqual(lists:sort([QName, <<"cc 1">>, <<"cc 2">>]),
1425+
lists:sort(RKeys)).
14201426

14211427
%% Three top-level headers are added for the very first dead-lettering event.
14221428
%% They are
@@ -1681,7 +1687,11 @@ stream(Config) ->
16811687
#'basic.publish'{routing_key = Q1},
16821688
#amqp_msg{payload = Payload,
16831689
props = #'P_basic'{expiration = <<"0">>,
1684-
headers = [{<<"CC">>, array, [{longstr, <<"other key">>}]}]}
1690+
headers = [{<<"CC">>, array, [{longstr, <<"cc 1">>},
1691+
{longstr, <<"cc 2">>}]},
1692+
{<<"BCC">>, array, [{longstr, <<"bcc 1">>},
1693+
{longstr, <<"bcc 2">>}]}
1694+
]}
16851695
}),
16861696

16871697
#'basic.qos_ok'{} = amqp_channel:call(Ch1, #'basic.qos'{prefetch_count = 1}),
@@ -1722,7 +1732,10 @@ stream(Config) ->
17221732
?assertEqual({longstr, Reason}, rabbit_misc:table_lookup(Death1, <<"reason">>)),
17231733
?assertEqual({longstr, <<>>}, rabbit_misc:table_lookup(Death1, <<"exchange">>)),
17241734
?assertEqual({long, 1}, rabbit_misc:table_lookup(Death1, <<"count">>)),
1725-
?assertEqual({array, [{longstr, Q1}, {longstr, <<"other key">>}]},
1735+
%% routing-keys in the death history should include CC but exclude BCC keys
1736+
?assertEqual({array, [{longstr, Q1},
1737+
{longstr, <<"cc 1">>},
1738+
{longstr, <<"cc 2">>}]},
17261739
rabbit_misc:table_lookup(Death1, <<"routing-keys">>)),
17271740
?assertEqual({longstr, <<"0">>}, rabbit_misc:table_lookup(Death1, <<"original-expiration">>)),
17281741
{timestamp, T1} = rabbit_misc:table_lookup(Death1, <<"time">>),

0 commit comments

Comments
 (0)