Skip to content

Commit ebbff46

Browse files
authored
Merge pull request #11307 from rabbitmq/amqp-flow-control-poc-2
Introduce outbound RabbitMQ internal AMQP flow control
2 parents 5f659b5 + cf3c8ba commit ebbff46

18 files changed

+1269
-345
lines changed

deps/amqp10_client/src/amqp10_client_frame_reader.erl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,18 @@ handle_input(StateName, Data, State) ->
286286
defer_heartbeat_timer(State =
287287
#state{heartbeat_timer_ref = TRef,
288288
connection_config = #{idle_time_out := T}})
289-
when is_number(T) andalso T > 0 ->
289+
when is_integer(T) andalso T > 0 ->
290290
_ = case TRef of
291-
undefined -> ok;
292-
_ -> _ = erlang:cancel_timer(TRef)
291+
undefined ->
292+
ok;
293+
_ ->
294+
erlang:cancel_timer(TRef, [{async, true},
295+
{info, false}])
293296
end,
294297
NewTRef = erlang:send_after(T * 2, self(), heartbeat),
295298
State#state{heartbeat_timer_ref = NewTRef};
296-
defer_heartbeat_timer(State) -> State.
299+
defer_heartbeat_timer(State) ->
300+
State.
297301

298302
route_frame(Channel, FrameType, {Performative, Payload} = Frame, State0) ->
299303
{DestinationPid, State} = find_destination(Channel, FrameType, Performative,

deps/amqp10_client/src/amqp10_client_session.erl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,9 +902,10 @@ handle_link_flow(#'v1_0.flow'{delivery_count = MaybeTheirDC,
902902
handle_link_flow(#'v1_0.flow'{delivery_count = TheirDC,
903903
link_credit = {uint, TheirCredit},
904904
available = Available,
905-
drain = Drain},
905+
drain = Drain0},
906906
Link0 = #link{role = receiver}) ->
907-
Link = case Drain andalso TheirCredit =< 0 of
907+
Drain = default(Drain0, false),
908+
Link = case Drain andalso TheirCredit =:= 0 of
908909
true ->
909910
notify_credit_exhausted(Link0),
910911
Link0#link{delivery_count = unpack(TheirDC),
@@ -1212,6 +1213,9 @@ boolean_to_role(?AMQP_ROLE_SENDER) ->
12121213
boolean_to_role(?AMQP_ROLE_RECEIVER) ->
12131214
receiver.
12141215

1216+
default(undefined, Default) -> Default;
1217+
default(Thing, _Default) -> Thing.
1218+
12151219
format_status(Status = #{data := Data0}) ->
12161220
#state{channel = Channel,
12171221
remote_channel = RemoteChannel,

deps/rabbit/src/rabbit_amqp_management.erl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
-import(rabbit_amqp_session,
99
[check_resource_access/4,
1010
check_read_permitted_on_topic/4]).
11+
-import(rabbit_misc,
12+
[queue_resource/2,
13+
exchange_resource/2]).
1114

1215
-type permission_caches() :: {rabbit_amqp_session:permission_cache(),
1316
rabbit_amqp_session:topic_permission_cache()}.
@@ -78,7 +81,7 @@ handle_http_req(<<"GET">>,
7881
_ConnPid,
7982
PermCaches) ->
8083
QNameBin = uri_string:unquote(QNameBinQuoted),
81-
QName = rabbit_misc:r(Vhost, queue, QNameBin),
84+
QName = queue_resource(Vhost, QNameBin),
8285
case rabbit_amqqueue:with(
8386
QName,
8487
fun(Q) ->
@@ -119,7 +122,7 @@ handle_http_req(HttpMethod = <<"PUT">>,
119122
_ -> ok
120123
end,
121124
ok = prohibit_cr_lf(QNameBin),
122-
QName = rabbit_misc:r(Vhost, queue, QNameBin),
125+
QName = queue_resource(Vhost, QNameBin),
123126
ok = prohibit_reserved_amq(QName),
124127
PermCache1 = check_resource_access(QName, configure, User, PermCache0),
125128
rabbit_core_metrics:queue_declared(QName),
@@ -193,7 +196,7 @@ handle_http_req(<<"PUT">>,
193196
catch exit:#amqp_error{explanation = Explanation} ->
194197
throw(<<"400">>, Explanation, [])
195198
end,
196-
XName = rabbit_misc:r(Vhost, exchange, XNameBin),
199+
XName = exchange_resource(Vhost, XNameBin),
197200
ok = prohibit_default_exchange(XName),
198201
PermCache = check_resource_access(XName, configure, User, PermCache0),
199202
X = case rabbit_exchange:lookup(XName) of
@@ -224,7 +227,7 @@ handle_http_req(<<"DELETE">>,
224227
ConnPid,
225228
{PermCache0, TopicPermCache}) ->
226229
QNameBin = uri_string:unquote(QNameBinQuoted),
227-
QName = rabbit_misc:r(Vhost, queue, QNameBin),
230+
QName = queue_resource(Vhost, QNameBin),
228231
PermCache = check_resource_access(QName, read, User, PermCache0),
229232
try rabbit_amqqueue:with_exclusive_access_or_die(
230233
QName, ConnPid,
@@ -252,7 +255,7 @@ handle_http_req(<<"DELETE">>,
252255
ConnPid,
253256
{PermCache0, TopicPermCache}) ->
254257
QNameBin = uri_string:unquote(QNameBinQuoted),
255-
QName = rabbit_misc:r(Vhost, queue, QNameBin),
258+
QName = queue_resource(Vhost, QNameBin),
256259
ok = prohibit_cr_lf(QNameBin),
257260
PermCache = check_resource_access(QName, configure, User, PermCache0),
258261
try rabbit_amqqueue:delete_with(QName, ConnPid, false, false, Username, true) of
@@ -272,7 +275,7 @@ handle_http_req(<<"DELETE">>,
272275
_ConnPid,
273276
{PermCache0, TopicPermCache}) ->
274277
XNameBin = uri_string:unquote(XNameBinQuoted),
275-
XName = rabbit_misc:r(Vhost, exchange, XNameBin),
278+
XName = exchange_resource(Vhost, XNameBin),
276279
ok = prohibit_cr_lf(XNameBin),
277280
ok = prohibit_default_exchange(XName),
278281
ok = prohibit_reserved_amq(XName),
@@ -297,7 +300,7 @@ handle_http_req(<<"POST">>,
297300
#{destination_exchange := Bin} ->
298301
{exchange, Bin}
299302
end,
300-
SrcXName = rabbit_misc:r(Vhost, exchange, SrcXNameBin),
303+
SrcXName = exchange_resource(Vhost, SrcXNameBin),
301304
DstName = rabbit_misc:r(Vhost, DstKind, DstNameBin),
302305
PermCaches = binding_checks(SrcXName, DstName, BindingKey, User, PermCaches0),
303306
Binding = #binding{source = SrcXName,
@@ -320,7 +323,7 @@ handle_http_req(<<"DELETE">>,
320323
DstNameBin,
321324
BindingKey,
322325
ArgsHash} = decode_binding_path_segment(BindingSegment),
323-
SrcXName = rabbit_misc:r(Vhost, exchange, SrcXNameBin),
326+
SrcXName = exchange_resource(Vhost, SrcXNameBin),
324327
DstName = rabbit_misc:r(Vhost, DstKind, DstNameBin),
325328
PermCaches = binding_checks(SrcXName, DstName, BindingKey, User, PermCaches0),
326329
Bindings = rabbit_binding:list_for_source_and_destination(SrcXName, DstName),
@@ -352,7 +355,7 @@ handle_http_req(<<"GET">>,
352355
"missing 'dste' or 'dstq' in query: ~tp",
353356
QueryMap)
354357
end,
355-
SrcXName = rabbit_misc:r(Vhost, exchange, SrcXNameBin),
358+
SrcXName = exchange_resource(Vhost, SrcXNameBin),
356359
DstName = rabbit_misc:r(Vhost, DstKind, DstNameBin),
357360
Bindings0 = rabbit_binding:list_for_source_and_destination(SrcXName, DstName),
358361
Bindings = [B || B = #binding{key = K} <- Bindings0, K =:= Key],

0 commit comments

Comments
 (0)