use of com.rabbitmq.client.QueueingConsumer in project rabbitmq-java-client by rabbitmq.
the class QosTests method consumerLifecycle.
@Test
public void consumerLifecycle() throws IOException {
channel.basicQos(1, true);
QueueingConsumer c = new QueueingConsumer(channel);
String queue = "qosTest";
channel.queueDeclare(queue, false, false, false, null);
channel.queueBind(queue, "amq.fanout", "");
fill(3);
String tag;
for (int i = 0; i < 2; i++) {
tag = channel.basicConsume(queue, false, c);
List<Delivery> d = drain(c, 1);
channel.basicCancel(tag);
drain(c, 0);
ack(d, true);
drain(c, 0);
}
channel.queueDelete(queue);
}
use of com.rabbitmq.client.QueueingConsumer in project rabbitmq-java-client by rabbitmq.
the class QosTests method limitingMultipleChannels.
@Test
public void limitingMultipleChannels() throws IOException {
Channel ch1 = connection.createChannel();
Channel ch2 = connection.createChannel();
QueueingConsumer c1 = new QueueingConsumer(ch1);
QueueingConsumer c2 = new QueueingConsumer(ch2);
String q1 = declareBindConsume(ch1, c1, false);
String q2 = declareBindConsume(ch2, c2, false);
ch1.basicConsume(q2, false, c1);
ch2.basicConsume(q1, false, c2);
ch1.basicQos(1, true);
ch2.basicQos(1, true);
fill(5);
List<Delivery> d1 = drain(c1, 1);
List<Delivery> d2 = drain(c2, 1);
ackDelivery(ch1, d1.remove(0), true);
ackDelivery(ch2, d2.remove(0), true);
drain(c1, 1);
drain(c2, 1);
ch1.abort();
ch2.abort();
}
use of com.rabbitmq.client.QueueingConsumer in project rabbitmq-java-client by rabbitmq.
the class QosTests method fairness.
@Test
public void fairness() throws IOException {
QueueingConsumer c = new QueueingConsumer(channel);
final int queueCount = 3;
final int messageCount = 100;
List<String> queues = configure(c, 1, queueCount, messageCount);
for (int i = 0; i < messageCount - 1; i++) {
List<Delivery> d = drain(c, 1);
ack(d, false);
}
// probably good enough.
for (String q : queues) {
AMQP.Queue.DeclareOk ok = channel.queueDeclarePassive(q);
assertTrue(ok.getMessageCount() < messageCount);
}
}
use of com.rabbitmq.client.QueueingConsumer in project rabbitmq-java-client by rabbitmq.
the class QosTests method runLimitTests.
protected void runLimitTests(int limit, boolean multiAck, boolean txMode, int queueCount) throws IOException {
QueueingConsumer c = new QueueingConsumer(channel);
// We attempt to drain 'limit' messages twice, do one
// basic.get per queue, and need one message to spare
// -> 2*limit + 1*queueCount + 1
List<String> queues = configure(c, limit, queueCount, 2 * limit + 1 * queueCount + 1);
if (txMode) {
channel.txSelect();
}
// is limit enforced?
List<Delivery> d = drain(c, limit);
// is basic.get not limited?
List<Long> tags = new ArrayList<Long>();
for (String q : queues) {
GetResponse r = channel.basicGet(q, false);
assertNotNull(r);
tags.add(r.getEnvelope().getDeliveryTag());
}
// are acks handled correctly?
// and does the basic.get above have no effect on limiting?
Delivery last = ack(d, multiAck);
if (txMode) {
drain(c, 0);
channel.txRollback();
drain(c, 0);
ackDelivery(last, true);
channel.txCommit();
}
drain(c, limit);
// do acks for basic.gets have no effect on limiting?
for (long t : tags) {
channel.basicAck(t, false);
}
if (txMode) {
channel.txCommit();
}
drain(c, 0);
}
use of com.rabbitmq.client.QueueingConsumer in project rabbitmq-java-client by rabbitmq.
the class Reject method reject.
@Test
public void reject() throws Exception {
String q = queueCreator.apply(channel);
channel.confirmSelect();
byte[] m1 = "1".getBytes();
byte[] m2 = "2".getBytes();
basicPublishVolatile(m1, q);
basicPublishVolatile(m2, q);
channel.waitForConfirmsOrDie(1000);
long tag1 = checkDelivery(channel.basicGet(q, false), m1, false);
long tag2 = checkDelivery(channel.basicGet(q, false), m2, false);
QueueingConsumer c = new QueueingConsumer(secondaryChannel);
String consumerTag = secondaryChannel.basicConsume(q, false, c);
channel.basicReject(tag2, true);
long tag3 = checkDelivery(c.nextDelivery(), m2, true);
secondaryChannel.basicCancel(consumerTag);
secondaryChannel.basicReject(tag3, false);
assertNull(channel.basicGet(q, false));
channel.basicAck(tag1, false);
channel.basicReject(tag3, false);
expectError(AMQP.PRECONDITION_FAILED);
}
Aggregations