try {
q = new QueueingConsumer(channel);
channel.basicConsume(queueName, autoAck, q);
while (timeLimit == 0 || now < startTime + timeLimit) {
Delivery delivery;
try {
if (timeLimit == 0) {
delivery = q.nextDelivery();
} else {
delivery = q.nextDelivery(startTime + timeLimit - now);
if (delivery == null) break;
}
} catch (ConsumerCancelledException e) {
System.out.println("Consumer cancelled by broker. Re-consuming.");
q = new QueueingConsumer(channel);
channel.basicConsume(queueName, autoAck, q);
continue;
}
totalMsgCount++;
DataInputStream d = new DataInputStream(new ByteArrayInputStream(delivery.getBody()));
d.readInt();
long msgNano = d.readLong();
long nano = System.nanoTime();
Envelope envelope = delivery.getEnvelope();
if (!autoAck) {
if (multiAckEvery == 0) {
channel.basicAck(envelope.getDeliveryTag(), false);
} else if (totalMsgCount % multiAckEvery == 0) {