use of com.rabbitmq.client.QueueingConsumer in project rabbitmq-java-client by rabbitmq.
the class QosTests method noAckObeysLimit.
@Test
public void noAckObeysLimit() throws IOException {
channel.basicQos(1, true);
QueueingConsumer c1 = new QueueingConsumer(channel);
declareBindConsume(channel, c1, false);
fill(1);
QueueingConsumer c2 = new QueueingConsumer(channel);
declareBindConsume(channel, c2, true);
fill(1);
try {
Delivery d = c2.nextDelivery(1000);
assertNull(d);
} catch (InterruptedException ie) {
fail("interrupted");
}
List<Delivery> d = drain(c1, 1);
// must ack before the next one appears
ack(d, false);
d = drain(c1, 1);
ack(d, false);
drain(c2, 1);
}
use of com.rabbitmq.client.QueueingConsumer in project rabbitmq-java-client by rabbitmq.
the class QosTests method messageLimitUnlimited.
@Test
public void messageLimitUnlimited() throws IOException {
QueueingConsumer c = new QueueingConsumer(channel);
configure(c, 0, 1, 2);
drain(c, 2);
}
use of com.rabbitmq.client.QueueingConsumer in project rabbitmq-java-client by rabbitmq.
the class Nack method singleNack.
@Test
public void singleNack() throws Exception {
String q = queueCreator.apply(channel);
byte[] m1 = "1".getBytes();
byte[] m2 = "2".getBytes();
channel.confirmSelect();
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);
// requeue
channel.basicNack(tag2, false, true);
long tag3 = checkDelivery(c.nextDelivery(), m2, true);
secondaryChannel.basicCancel(consumerTag);
// no requeue
secondaryChannel.basicNack(tag3, false, false);
assertNull(channel.basicGet(q, false));
channel.basicAck(tag1, false);
channel.basicNack(tag3, false, true);
expectError(AMQP.PRECONDITION_FAILED);
}
use of com.rabbitmq.client.QueueingConsumer in project rabbitmq-java-client by rabbitmq.
the class QueueingConsumerTests method nThreadShutdown.
@Test
public void nThreadShutdown() throws Exception {
Channel channel = connection.createChannel();
final QueueingConsumer c = new QueueingConsumer(channel);
channel.queueDeclare(QUEUE, false, true, true, null);
channel.basicConsume(QUEUE, c);
final AtomicInteger count = new AtomicInteger(THREADS);
final CountDownLatch latch = new CountDownLatch(THREADS);
for (int i = 0; i < THREADS; i++) {
new Thread() {
@Override
public void run() {
try {
while (true) {
c.nextDelivery();
}
} catch (ShutdownSignalException sig) {
count.decrementAndGet();
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
latch.countDown();
}
}
}.start();
}
connection.close();
// Far longer than this could reasonably take
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertEquals(0, count.get());
}
use of com.rabbitmq.client.QueueingConsumer in project rabbitmq-java-client by rabbitmq.
the class BindingLifecycleBase method doAutoDelete.
protected void doAutoDelete(boolean durable, int queues) throws IOException, TimeoutException {
String[] queueNames = null;
Binding binding = Binding.randomBinding();
channel.exchangeDeclare(binding.x, "direct", durable, true, null);
channel.queueDeclare(binding.q, durable, false, true, null);
channel.queueBind(binding.q, binding.x, binding.k);
if (queues > 1) {
int j = queues - 1;
queueNames = new String[j];
for (int i = 0; i < j; i++) {
queueNames[i] = randomString();
channel.queueDeclare(queueNames[i], durable, false, false, null);
channel.queueBind(queueNames[i], binding.x, binding.k);
channel.basicConsume(queueNames[i], true, new QueueingConsumer(channel));
}
}
subscribeSendUnsubscribe(binding);
if (durable) {
restart();
}
if (queues > 1 && queueNames != null) {
for (String s : queueNames) {
channel.basicConsume(s, true, new QueueingConsumer(channel));
Binding tmp = new Binding(s, binding.x, binding.k);
sendUnroutable(tmp);
}
}
channel.queueDeclare(binding.q, durable, true, true, null);
// bind should fail
try {
channel.queueBind(binding.q, binding.x, binding.k);
sendRoutable(binding);
} catch (IOException e) {
checkShutdownSignal(AMQP.NOT_FOUND, e);
channel = null;
return;
}
if (queues == 1) {
deleteExchangeAndQueue(binding);
fail("Queue bind should have failed");
}
// Do some cleanup
if (queues > 1 && queueNames != null) {
for (String q : queueNames) {
channel.queueDelete(q);
}
}
}
Aggregations