channel.queueBind(q, "amq.fanout", "");
final Map<String, Integer> counts =
Collections.synchronizedMap(new HashMap<String, Integer>());
QueueingConsumer c = new QueueingConsumer(channel) {
@Override public void handleDelivery(String consumerTag,
Envelope envelope,
AMQP.BasicProperties properties,
byte[] body)
throws IOException {
counts.put(consumerTag, counts.get(consumerTag) + 1);
super.handleDelivery(consumerTag, envelope,
properties, body);
}
};
channel.basicConsume(q, false, "c1", c);
channel.basicConsume(q, false, "c2", c);
int count = 10;
counts.put("c1", 0);
counts.put("c2", 0);
fill(count);
try {
for (int i = 0; i < count; i++) {
Delivery d = c.nextDelivery();
channel.basicAck(d.getEnvelope().getDeliveryTag(), false);
}
} catch (InterruptedException ie) {
fail("interrupted");
}