Skip to content

Commit

Permalink
Set durable annotation for AMQP messages
Browse files Browse the repository at this point in the history
This is similar to #11057

What?
For incoming AMQP messages, always set the durable message container annotation.

Why?
Even though defaulting to durable=true when no durable annotation is set, as prior
to this commit, is good enough, explicitly setting the durable annotation makes
the code a bit more future proof and maintainable going forward in 4.0 where we
will rely more on the durable annotation because AMQP 1.0 message headers will
be omitted in classic and quorum queues.

The performance impact of always setting the durable annotation is negligible.
  • Loading branch information
ansd committed May 2, 2024
1 parent b721b1a commit 4209f3f
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions deps/rabbit/src/mc_amqp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
]).

-import(rabbit_misc,
[maps_put_truthy/3,
maps_put_falsy/3
]).
[maps_put_truthy/3]).

-type message_section() ::
#'v1_0.header'{} |
Expand Down Expand Up @@ -185,8 +183,6 @@ get_property(durable, Msg) ->
#msg_body_encoded{header = #'v1_0.header'{durable = Durable}}
when is_boolean(Durable) ->
Durable;
#msg_body_encoded{header = #'v1_0.header'{durable = {boolean, Durable}}} ->
Durable;
_ ->
%% fallback in case the source protocol was old AMQP 0.9.1
case message_annotation(<<"x-basic-delivery-mode">>, Msg, undefined) of
Expand Down Expand Up @@ -644,17 +640,16 @@ essential_properties(#msg_body_encoded{message_annotations = MA} = Msg) ->
_ ->
undefined
end,
Anns = maps_put_falsy(
?ANN_DURABLE, Durable,
Anns0 = #{?ANN_DURABLE => Durable},
Anns = maps_put_truthy(
?ANN_PRIORITY, Priority,
maps_put_truthy(
?ANN_PRIORITY, Priority,
?ANN_TIMESTAMP, Timestamp,
maps_put_truthy(
?ANN_TIMESTAMP, Timestamp,
ttl, Ttl,
maps_put_truthy(
ttl, Ttl,
maps_put_truthy(
deaths, Deaths,
#{}))))),
deaths, Deaths,
Anns0)))),
case MA of
[] ->
Anns;
Expand Down

0 comments on commit 4209f3f

Please sign in to comment.