Skip to content

Commit c0fbc1a

Browse files
committed
Fix AMQP 1.0 shovel
The shovel violated the AMQP 1.0 spec by sending transfers with settled=true under sender settle mode unsettled (in case of shovel ack-mode being on-publish).
1 parent 9d7ebf3 commit c0fbc1a

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

deps/rabbitmq_shovel/src/rabbit_amqp10_shovel.erl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,13 @@ connect_source(State = #{name := Name,
7474
ack_mode := AckMode,
7575
source := #{uris := [Uri | _],
7676
source_address := Addr} = Src}) ->
77+
SndSettleMode = case AckMode of
78+
no_ack -> settled;
79+
on_publish -> unsettled;
80+
on_confirm -> unsettled
81+
end,
7782
AttachFun = fun amqp10_client:attach_receiver_link/5,
78-
{Conn, Sess, LinkRef} = connect(Name, AckMode, Uri, "receiver", Addr, Src,
83+
{Conn, Sess, LinkRef} = connect(Name, SndSettleMode, Uri, "receiver", Addr, Src,
7984
AttachFun),
8085
State#{source => Src#{current => #{conn => Conn,
8186
session => Sess,
@@ -87,8 +92,13 @@ connect_dest(State = #{name := Name,
8792
ack_mode := AckMode,
8893
dest := #{uris := [Uri | _],
8994
target_address := Addr} = Dst}) ->
95+
SndSettleMode = case AckMode of
96+
no_ack -> settled;
97+
on_publish -> settled;
98+
on_confirm -> unsettled
99+
end,
90100
AttachFun = fun amqp10_client:attach_sender_link_sync/5,
91-
{Conn, Sess, LinkRef} = connect(Name, AckMode, Uri, "sender", Addr, Dst,
101+
{Conn, Sess, LinkRef} = connect(Name, SndSettleMode, Uri, "sender", Addr, Dst,
92102
AttachFun),
93103
%% wait for link credit here as if there are messages waiting we may try
94104
%% to forward before we've received credit
@@ -99,7 +109,7 @@ connect_dest(State = #{name := Name,
99109
link => LinkRef,
100110
uri => Uri}}}.
101111

102-
connect(Name, AckMode, Uri, Postfix, Addr, Map, AttachFun) ->
112+
connect(Name, SndSettleMode, Uri, Postfix, Addr, Map, AttachFun) ->
103113
{ok, Config0} = amqp10_client:parse_uri(Uri),
104114
%% As done for AMQP 0.9.1, exclude AMQP 1.0 shovel connections from maintenance mode
105115
%% to prevent crashes and errors being logged by the shovel plugin when a node gets drained.
@@ -113,16 +123,11 @@ connect(Name, AckMode, Uri, Postfix, Addr, Map, AttachFun) ->
113123
LinkName0 = gen_unique_name(Name, Postfix),
114124
rabbit_data_coercion:to_binary(LinkName0)
115125
end,
116-
% mixed settlement mode covers all the ack_modes
117-
SettlementMode = case AckMode of
118-
no_ack -> settled;
119-
_ -> unsettled
120-
end,
121126
% needs to be sync, i.e. awaits the 'attach' event as
122127
% else we may try to use the link before it is ready
123128
Durability = maps:get(durability, Map, unsettled_state),
124129
{ok, LinkRef} = AttachFun(Sess, LinkName, Addr,
125-
SettlementMode,
130+
SndSettleMode,
126131
Durability),
127132
{Conn, Sess, LinkRef}.
128133

0 commit comments

Comments
 (0)