@@ -386,15 +386,24 @@ init([Channel, ReaderPid, WriterPid, ConnPid, ConnName, Protocol, User, VHost,
386
386
true -> flow ;
387
387
false -> noflow
388
388
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 ,
390
399
State = # ch {state = starting ,
391
400
protocol = Protocol ,
392
401
channel = Channel ,
393
402
reader_pid = ReaderPid ,
394
403
writer_pid = WriterPid ,
395
404
conn_pid = ConnPid ,
396
405
conn_name = ConnName ,
397
- limiter = rabbit_limiter : new ( LimiterPid ) ,
406
+ limiter = Limiter ,
398
407
tx = none ,
399
408
next_tag = 1 ,
400
409
unacked_message_q = queue :new (),
@@ -414,7 +423,7 @@ init([Channel, ReaderPid, WriterPid, ConnPid, ConnName, Protocol, User, VHost,
414
423
mandatory = dtree :empty (),
415
424
capabilities = Capabilities ,
416
425
trace_state = rabbit_trace :init (VHost ),
417
- consumer_prefetch = 0 ,
426
+ consumer_prefetch = Prefetch ,
418
427
reply_consumer = none ,
419
428
delivery_flow = Flow ,
420
429
interceptor_state = undefined },
@@ -1248,8 +1257,12 @@ handle_method(#'basic.qos'{prefetch_size = Size}, _, _State) when Size /= 0 ->
1248
1257
" prefetch_size!=0 (~w )" , [Size ]);
1249
1258
1250
1259
handle_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 }};
1253
1266
1254
1267
handle_method (# 'basic.qos' {global = true ,
1255
1268
prefetch_count = 0 },
0 commit comments