@@ -76,6 +76,7 @@ public static void main(String[] args) {
76
76
int consumerTxSize = intArg (cmd , 'n' , 0 );
77
77
long confirm = intArg (cmd , 'c' , -1 );
78
78
boolean autoAck = cmd .hasOption ('a' );
79
+ int multiAckEvery = intArg (cmd , 'A' , 0 );
79
80
int prefetchCount = intArg (cmd , 'q' , 0 );
80
81
int minMsgSize = intArg (cmd , 's' , 0 );
81
82
int timeLimit = intArg (cmd , 'z' , 0 );
@@ -120,7 +121,7 @@ public static void main(String[] args) {
120
121
Thread t =
121
122
new Thread (new Consumer (channel , id , qName ,
122
123
consumerTxSize , autoAck ,
123
- stats , timeLimit ));
124
+ multiAckEvery , stats , timeLimit ));
124
125
consumerThreads [i ] = t ;
125
126
}
126
127
Thread [] producerThreads = new Thread [producerCount ];
@@ -183,27 +184,28 @@ private static void usage(Options options) {
183
184
184
185
private static Options getOptions () {
185
186
Options options = new Options ();
186
- options .addOption (new Option ("?" , "help" , false ,"show usage" ));
187
- options .addOption (new Option ("h" , "uri" , true , "AMQP URI" ));
188
- options .addOption (new Option ("t" , "type" , true , "exchange type" ));
189
- options .addOption (new Option ("e" , "exchange" , true , "exchange name" ));
190
- options .addOption (new Option ("u" , "queue" , true , "queue name" ));
191
- options .addOption (new Option ("i" , "interval" , true , "sampling interval" ));
192
- options .addOption (new Option ("r" , "rate" , true , "rate limit" ));
193
- options .addOption (new Option ("x" , "producers" , true , "producer count" ));
194
- options .addOption (new Option ("y" , "consumers" , true , "consumer count" ));
195
- options .addOption (new Option ("m" , "ptxsize" , true , "producer tx size" ));
196
- options .addOption (new Option ("n" , "ctxsize" , true , "consumer tx size" ));
197
- options .addOption (new Option ("c" , "confirm" , true , "max unconfirmed publishes" ));
198
- options .addOption (new Option ("a" , "autoack" , false ,"auto ack" ));
199
- options .addOption (new Option ("q" , "qos" , true , "qos prefetch count" ));
200
- options .addOption (new Option ("s" , "size" , true , "message size" ));
201
- options .addOption (new Option ("z" , "time" , true , "time limit" ));
202
- Option flag = new Option ("f" , "flag" , true , "message flag" );
187
+ options .addOption (new Option ("?" , "help" , false ,"show usage" ));
188
+ options .addOption (new Option ("h" , "uri" , true , "AMQP URI" ));
189
+ options .addOption (new Option ("t" , "type" , true , "exchange type" ));
190
+ options .addOption (new Option ("e" , "exchange" , true , "exchange name" ));
191
+ options .addOption (new Option ("u" , "queue" , true , "queue name" ));
192
+ options .addOption (new Option ("i" , "interval" , true , "sampling interval" ));
193
+ options .addOption (new Option ("r" , "rate" , true , "rate limit" ));
194
+ options .addOption (new Option ("x" , "producers" , true , "producer count" ));
195
+ options .addOption (new Option ("y" , "consumers" , true , "consumer count" ));
196
+ options .addOption (new Option ("m" , "ptxsize" , true , "producer tx size" ));
197
+ options .addOption (new Option ("n" , "ctxsize" , true , "consumer tx size" ));
198
+ options .addOption (new Option ("c" , "confirm" , true , "max unconfirmed publishes" ));
199
+ options .addOption (new Option ("a" , "autoack" , false ,"auto ack" ));
200
+ options .addOption (new Option ("A" , "multiAckEvery" , true , "multi ack every" ));
201
+ options .addOption (new Option ("q" , "qos" , true , "qos prefetch count" ));
202
+ options .addOption (new Option ("s" , "size" , true , "message size" ));
203
+ options .addOption (new Option ("z" , "time" , true , "time limit" ));
204
+ Option flag = new Option ("f" , "flag" , true , "message flag" );
203
205
flag .setArgs (Option .UNLIMITED_VALUES );
204
206
options .addOption (flag );
205
- options .addOption (new Option ("M" , "framemax" , true , "frame max" ));
206
- options .addOption (new Option ("b" , "heartbeat" , true , "heartbeat interval" ));
207
+ options .addOption (new Option ("M" , "framemax" , true , "frame max" ));
208
+ options .addOption (new Option ("b" , "heartbeat" , true , "heartbeat interval" ));
207
209
return options ;
208
210
}
209
211
@@ -410,20 +412,22 @@ public static class Consumer implements Runnable {
410
412
private String queueName ;
411
413
private int txSize ;
412
414
private boolean autoAck ;
415
+ private int multiAckEvery ;
413
416
private Stats stats ;
414
417
private long timeLimit ;
415
418
416
419
public Consumer (Channel channel , String id ,
417
420
String queueName , int txSize , boolean autoAck ,
418
- Stats stats , int timeLimit ) {
419
-
420
- this .channel = channel ;
421
- this .id = id ;
422
- this .queueName = queueName ;
423
- this .txSize = txSize ;
424
- this .autoAck = autoAck ;
425
- this .stats = stats ;
426
- this .timeLimit = 1000L * timeLimit ;
421
+ int multiAckEvery , Stats stats , int timeLimit ) {
422
+
423
+ this .channel = channel ;
424
+ this .id = id ;
425
+ this .queueName = queueName ;
426
+ this .txSize = txSize ;
427
+ this .autoAck = autoAck ;
428
+ this .multiAckEvery = multiAckEvery ;
429
+ this .stats = stats ;
430
+ this .timeLimit = 1000L * timeLimit ;
427
431
}
428
432
429
433
public void run () {
@@ -462,7 +466,11 @@ public void run() {
462
466
Envelope envelope = delivery .getEnvelope ();
463
467
464
468
if (!autoAck ) {
465
- channel .basicAck (envelope .getDeliveryTag (), false );
469
+ if (multiAckEvery == 0 ) {
470
+ channel .basicAck (envelope .getDeliveryTag (), false );
471
+ } else if (totalMsgCount % multiAckEvery == 0 ) {
472
+ channel .basicAck (envelope .getDeliveryTag (), true );
473
+ }
466
474
}
467
475
468
476
if (txSize != 0 && totalMsgCount % txSize == 0 ) {
0 commit comments