@@ -386,15 +386,24 @@ init([Channel, ReaderPid, WriterPid, ConnPid, ConnName, Protocol, User, VHost,
386386 true -> flow ;
387387 false -> noflow
388388 end ,
389-
389+ {ok , {Global , Prefetch }} = application :get_env (rabbit , default_consumer_prefetch ),
390+ Limiter0 = rabbit_limiter :new (LimiterPid ),
391+ Limiter = case {Global , Prefetch } of
392+ {true , 0 } ->
393+ rabbit_limiter :unlimit_prefetch (Limiter0 );
394+ {true , _ } ->
395+ rabbit_limiter :limit_prefetch (Limiter0 , Prefetch , 0 );
396+ _ ->
397+ Limiter0
398+ end ,
390399 State = # ch {state = starting ,
391400 protocol = Protocol ,
392401 channel = Channel ,
393402 reader_pid = ReaderPid ,
394403 writer_pid = WriterPid ,
395404 conn_pid = ConnPid ,
396405 conn_name = ConnName ,
397- limiter = rabbit_limiter : new ( LimiterPid ) ,
406+ limiter = Limiter ,
398407 tx = none ,
399408 next_tag = 1 ,
400409 unacked_message_q = queue :new (),
@@ -414,7 +423,7 @@ init([Channel, ReaderPid, WriterPid, ConnPid, ConnName, Protocol, User, VHost,
414423 mandatory = dtree :empty (),
415424 capabilities = Capabilities ,
416425 trace_state = rabbit_trace :init (VHost ),
417- consumer_prefetch = 0 ,
426+ consumer_prefetch = Prefetch ,
418427 reply_consumer = none ,
419428 delivery_flow = Flow ,
420429 interceptor_state = undefined },
@@ -1248,8 +1257,12 @@ handle_method(#'basic.qos'{prefetch_size = Size}, _, _State) when Size /= 0 ->
12481257 " prefetch_size!=0 (~w )" , [Size ]);
12491258
12501259handle_method (# 'basic.qos' {global = false ,
1251- prefetch_count = PrefetchCount }, _ , State ) ->
1252- {reply , # 'basic.qos_ok' {}, State # ch {consumer_prefetch = PrefetchCount }};
1260+ prefetch_count = PrefetchCount },
1261+ _ , State = # ch {limiter = Limiter }) ->
1262+ % % Ensures that if default was set, it's overriden
1263+ Limiter1 = rabbit_limiter :unlimit_prefetch (Limiter ),
1264+ {reply , # 'basic.qos_ok' {}, State # ch {consumer_prefetch = PrefetchCount ,
1265+ limiter = Limiter1 }};
12531266
12541267handle_method (# 'basic.qos' {global = true ,
12551268 prefetch_count = 0 },
0 commit comments