Search in sources :

Example 46 with QueueingConsumer

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);
}
Also used : QueueingConsumer(com.rabbitmq.client.QueueingConsumer) Delivery(com.rabbitmq.client.QueueingConsumer.Delivery) Test(org.junit.Test)

Example 47 with QueueingConsumer

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();
}
Also used : Channel(com.rabbitmq.client.Channel) QueueingConsumer(com.rabbitmq.client.QueueingConsumer) Delivery(com.rabbitmq.client.QueueingConsumer.Delivery) Test(org.junit.Test)

Example 48 with QueueingConsumer

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);
    }
}
Also used : QueueingConsumer(com.rabbitmq.client.QueueingConsumer) Delivery(com.rabbitmq.client.QueueingConsumer.Delivery) Test(org.junit.Test)

Example 49 with QueueingConsumer

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);
}
Also used : QueueingConsumer(com.rabbitmq.client.QueueingConsumer) ArrayList(java.util.ArrayList) Delivery(com.rabbitmq.client.QueueingConsumer.Delivery) GetResponse(com.rabbitmq.client.GetResponse)

Example 50 with QueueingConsumer

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);
}
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