Search in sources :

Example 41 with QueueingConsumer

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

the class QosTests method limitIncrease.

@Test
public void limitIncrease() throws IOException {
    QueueingConsumer c = new QueueingConsumer(channel);
    configure(c, 1, 3);
    channel.basicQos(2, true);
    drain(c, 1);
}
Also used : QueueingConsumer(com.rabbitmq.client.QueueingConsumer) Test(org.junit.Test)

Example 42 with QueueingConsumer

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

the class QosTests method singleChannelAndQueueFairness.

@Test
public void singleChannelAndQueueFairness() throws IOException {
    // check that when we have multiple consumers on the same
    // channel & queue, and a prefetch limit set, that all
    // consumers get a fair share of the messages.
    channel.basicQos(1, true);
    String q = channel.queueDeclare().getQueue();
    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");
    }
    // we only check that the server isn't grossly unfair; perfect
    // fairness is too much to ask for (even though RabbitMQ atm
    // does actually provide it in this case)
    assertTrue(counts.get("c1").intValue() > 0);
    assertTrue(counts.get("c2").intValue() > 0);
}
Also used : QueueingConsumer(com.rabbitmq.client.QueueingConsumer) Delivery(com.rabbitmq.client.QueueingConsumer.Delivery) Envelope(com.rabbitmq.client.Envelope) Test(org.junit.Test)

Example 43 with QueueingConsumer

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

the class QosTests method limitInheritsUnackedCount.

@Test
public void limitInheritsUnackedCount() throws IOException {
    QueueingConsumer c = new QueueingConsumer(channel);
    declareBindConsume(c);
    fill(1);
    drain(c, 1);
    channel.basicQos(2, true);
    fill(2);
    drain(c, 1);
}
Also used : QueueingConsumer(com.rabbitmq.client.QueueingConsumer) Test(org.junit.Test)

Example 44 with QueueingConsumer

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

the class QosTests method limitDecrease.

@Test
public void limitDecrease() throws IOException {
    QueueingConsumer c = new QueueingConsumer(channel);
    List<Delivery> d = configure(c, 2, 4);
    channel.basicQos(1, true);
    drain(c, 0);
    ack(d, true);
    drain(c, 1);
}
Also used : QueueingConsumer(com.rabbitmq.client.QueueingConsumer) Delivery(com.rabbitmq.client.QueueingConsumer.Delivery) Test(org.junit.Test)

Example 45 with QueueingConsumer

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

the class QosTests method noAckNoAlterLimit.

@Test
public void noAckNoAlterLimit() throws IOException {
    QueueingConsumer c = new QueueingConsumer(channel);
    declareBindConsume(channel, c, true);
    channel.basicQos(1, true);
    fill(2);
    drain(c, 2);
}
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