Search in sources :

Example 11 with Delivery

use of com.rabbitmq.client.QueueingConsumer.Delivery 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 12 with Delivery

use of com.rabbitmq.client.QueueingConsumer.Delivery 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)

Aggregations

Delivery (com.rabbitmq.client.QueueingConsumer.Delivery)12 QueueingConsumer (com.rabbitmq.client.QueueingConsumer)9 Test (org.junit.Test)7 Channel (com.rabbitmq.client.Channel)2 Connection (com.rabbitmq.client.Connection)1 Envelope (com.rabbitmq.client.Envelope)1 GetResponse (com.rabbitmq.client.GetResponse)1 ShutdownListener (com.rabbitmq.client.ShutdownListener)1 ShutdownSignalException (com.rabbitmq.client.ShutdownSignalException)1 Firehose (io.druid.data.input.Firehose)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 ConnectionOptions (net.jodah.lyra.ConnectionOptions)1 Config (net.jodah.lyra.config.Config)1 RetryPolicy (net.jodah.lyra.retry.RetryPolicy)1