Search in sources :

Example 36 with QueueingConsumer

use of com.rabbitmq.client.QueueingConsumer in project rabbitmq-java-client by rabbitmq.

the class Nack method multiNack.

@Test
public void multiNack() throws Exception {
    String q = queueCreator.apply(channel);
    byte[] m1 = "1".getBytes();
    byte[] m2 = "2".getBytes();
    byte[] m3 = "3".getBytes();
    byte[] m4 = "4".getBytes();
    channel.confirmSelect();
    basicPublishVolatile(m1, q);
    basicPublishVolatile(m2, q);
    basicPublishVolatile(m3, q);
    basicPublishVolatile(m4, q);
    channel.waitForConfirmsOrDie(1000);
    checkDelivery(channel.basicGet(q, false), m1, false);
    long tag1 = checkDelivery(channel.basicGet(q, false), m2, false);
    checkDelivery(channel.basicGet(q, false), m3, false);
    long tag2 = checkDelivery(channel.basicGet(q, false), m4, false);
    // ack, leaving a gap in un-acked sequence
    channel.basicAck(tag1, false);
    QueueingConsumer c = new QueueingConsumer(secondaryChannel);
    String consumerTag = secondaryChannel.basicConsume(q, false, c);
    // requeue multi
    channel.basicNack(tag2, true, true);
    long tag3 = checkDeliveries(c, m1, m3, m4);
    secondaryChannel.basicCancel(consumerTag);
    // no requeue
    secondaryChannel.basicNack(tag3, true, false);
    assertNull(channel.basicGet(q, false));
    channel.basicNack(tag3, true, true);
    expectError(AMQP.PRECONDITION_FAILED);
}
Also used : QueueingConsumer(com.rabbitmq.client.QueueingConsumer) Test(org.junit.Test)

Example 37 with QueueingConsumer

use of com.rabbitmq.client.QueueingConsumer in project rabbitmq-java-client by rabbitmq.

the class PerMessageTTL method expiryWhenConsumerIsLateToTheParty.

@Test
public void expiryWhenConsumerIsLateToTheParty() throws Exception {
    declareAndBindQueue(500);
    publish(MSG[0]);
    this.sessionTTL = 100;
    publish(MSG[1]);
    Thread.sleep(200);
    QueueingConsumer c = new QueueingConsumer(channel);
    channel.basicConsume(TTL_QUEUE_NAME, c);
    assertNotNull("Message unexpectedly expired", c.nextDelivery(100));
    assertNull("Message should have been expired!!", c.nextDelivery(100));
}
Also used : QueueingConsumer(com.rabbitmq.client.QueueingConsumer) Test(org.junit.Test)

Example 38 with QueueingConsumer

use of com.rabbitmq.client.QueueingConsumer in project rabbitmq-java-client by rabbitmq.

the class PerConsumerPrefetch method autoAckIgnoresPrefetch.

@Test
public void autoAckIgnoresPrefetch() throws IOException {
    QueueingConsumer c = new QueueingConsumer(channel);
    publish(q, 10);
    consume(c, 1, true);
    drain(c, 10);
}
Also used : QueueingConsumer(com.rabbitmq.client.QueueingConsumer) Test(org.junit.Test)

Example 39 with QueueingConsumer

use of com.rabbitmq.client.QueueingConsumer in project rabbitmq-java-client by rabbitmq.

the class PerConsumerPrefetch method testPrefetch.

private void testPrefetch(Closure closure) throws IOException {
    QueueingConsumer c = new QueueingConsumer(channel);
    publish(q, 15);
    consume(c, 5, false);
    List<Delivery> deliveries = drain(c, 5);
    ack(channel.basicGet(q, false), false);
    drain(c, 0);
    closure.makeMore(deliveries);
    drain(c, 5);
}
Also used : QueueingConsumer(com.rabbitmq.client.QueueingConsumer) Delivery(com.rabbitmq.client.QueueingConsumer.Delivery)

Example 40 with QueueingConsumer

use of com.rabbitmq.client.QueueingConsumer in project rabbitmq-java-client by rabbitmq.

the class PerConsumerPrefetch method prefetchZeroMeansInfinity.

@Test
public void prefetchZeroMeansInfinity() throws IOException {
    QueueingConsumer c = new QueueingConsumer(channel);
    publish(q, 10);
    consume(c, 0, false);
    drain(c, 10);
}
Also used : QueueingConsumer(com.rabbitmq.client.QueueingConsumer) Test(org.junit.Test)

Aggregations

QueueingConsumer (com.rabbitmq.client.QueueingConsumer)55 Test (org.junit.Test)30 IOException (java.io.IOException)13 ConsumerCancelledException (com.rabbitmq.client.ConsumerCancelledException)12 ShutdownSignalException (com.rabbitmq.client.ShutdownSignalException)12 Channel (com.rabbitmq.client.Channel)11 Connection (com.rabbitmq.client.Connection)9 ConnectionFactory (com.rabbitmq.client.ConnectionFactory)9 Delivery (com.rabbitmq.client.QueueingConsumer.Delivery)9 AMQP (com.rabbitmq.client.AMQP)2 ArrayList (java.util.ArrayList)2 BasicProperties (com.rabbitmq.client.AMQP.BasicProperties)1 Queue (com.rabbitmq.client.AMQP.Queue)1 Envelope (com.rabbitmq.client.Envelope)1 GetResponse (com.rabbitmq.client.GetResponse)1 List (java.util.List)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 RabbitMQMessage (org.apache.axis2.transport.rabbitmq.RabbitMQMessage)1