Search in sources :

Example 31 with QueueingConsumer

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

the class QueueExclusivity method queueExclusiveForConsume.

@Test
public void queueExclusiveForConsume() throws Exception {
    QueueingConsumer c = new QueueingConsumer(channel);
    try {
        channel.basicConsume(q, c);
    } catch (IOException ioe) {
        checkShutdownSignal(AMQP.RESOURCE_LOCKED, ioe);
        return;
    }
    fail("Exclusive queue should be locked for basic consume from another connection");
}
Also used : QueueingConsumer(com.rabbitmq.client.QueueingConsumer) IOException(java.io.IOException) Test(org.junit.Test)

Example 32 with QueueingConsumer

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

the class QueueingConsumerTests method consumerCancellationInterruptsQueuingConsumerWait.

@Test
public void consumerCancellationInterruptsQueuingConsumerWait() throws IOException, InterruptedException {
    String queue = "cancel_notification_queue_for_queueing_consumer";
    final BlockingQueue<Boolean> result = new ArrayBlockingQueue<Boolean>(1);
    channel.queueDeclare(queue, false, true, false, null);
    final QueueingConsumer consumer = new QueueingConsumer(channel);
    Runnable receiver = new Runnable() {

        public void run() {
            try {
                try {
                    consumer.nextDelivery();
                } catch (ConsumerCancelledException e) {
                    result.put(true);
                    return;
                } catch (ShutdownSignalException e) {
                } catch (InterruptedException e) {
                }
                result.put(false);
            } catch (InterruptedException e) {
                fail();
            }
        }
    };
    Thread t = new Thread(receiver);
    t.start();
    channel.basicConsume(queue, consumer);
    channel.queueDelete(queue);
    assertTrue(result.take());
    t.join();
}
Also used : ConsumerCancelledException(com.rabbitmq.client.ConsumerCancelledException) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) ShutdownSignalException(com.rabbitmq.client.ShutdownSignalException) QueueingConsumer(com.rabbitmq.client.QueueingConsumer) Test(org.junit.Test)

Example 33 with QueueingConsumer

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

the class BindingLifecycleBase method subscribeSendUnsubscribe.

protected void subscribeSendUnsubscribe(Binding binding) throws IOException {
    String tag = channel.basicConsume(binding.q, new QueueingConsumer(channel));
    sendUnroutable(binding);
    channel.basicCancel(tag);
}
Also used : QueueingConsumer(com.rabbitmq.client.QueueingConsumer)

Example 34 with QueueingConsumer

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

the class ExchangeExchangeBindings method createResources.

@Override
protected void createResources() throws IOException {
    for (String q : queues) {
        channel.queueDeclare(q, false, false, false, null);
    }
    for (String e : exchanges) {
        channel.exchangeDeclare(e, "fanout");
    }
    for (String[] binding : bindings) {
        channel.queueBind(binding[0], binding[1], "");
    }
    for (int idx = 0; idx < consumers.length; ++idx) {
        QueueingConsumer consumer = new QueueingConsumer(channel);
        channel.basicConsume(queues[idx], true, consumer);
        consumers[idx] = consumer;
    }
}
Also used : QueueingConsumer(com.rabbitmq.client.QueueingConsumer)

Example 35 with QueueingConsumer

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

the class Nack method nackAll.

@Test
public void nackAll() 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);
    checkDelivery(channel.basicGet(q, false), m1, false);
    checkDelivery(channel.basicGet(q, false), m2, false);
    // nack all
    channel.basicNack(0, true, true);
    QueueingConsumer c = new QueueingConsumer(secondaryChannel);
    String consumerTag = secondaryChannel.basicConsume(q, true, c);
    checkDeliveries(c, m1, m2);
    secondaryChannel.basicCancel(consumerTag);
}
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