Search in sources :

Example 21 with DefaultConsumer

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

the class CloseInMainLoop method closeWithFaultyConsumer.

// The thrown runtime exception should get intercepted by the
// consumer exception handler, and result in a clean shut down.
@Test
public void closeWithFaultyConsumer() throws Exception {
    SpecialConnection connection = new SpecialConnection();
    Channel channel = connection.createChannel();
    channel.exchangeDeclare("x", "direct");
    channel.queueDeclare("q", false, false, false, null);
    channel.queueBind("q", "x", "k");
    channel.basicConsume("q", true, new DefaultConsumer(channel) {

        @Override
        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) {
            throw new RuntimeException("I am a bad consumer");
        }
    });
    channel.basicPublish("x", "k", null, new byte[10]);
    assertTrue(closeLatch.await(1000, TimeUnit.MILLISECONDS));
    assertTrue(connection.hadValidShutdown());
}
Also used : DefaultConsumer(com.rabbitmq.client.DefaultConsumer) AMQP(com.rabbitmq.client.AMQP) Channel(com.rabbitmq.client.Channel) Envelope(com.rabbitmq.client.Envelope) Test(org.junit.Test)

Example 22 with DefaultConsumer

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

the class Confirm method basicRejectRequeue.

@Test
public void basicRejectRequeue() throws IOException, InterruptedException, TimeoutException {
    basicRejectCommon(true);
    /* wait confirms to go through the broker */
    Thread.sleep(1000);
    channel.basicConsume("confirm-test-noconsumer", true, new DefaultConsumer(channel));
    channel.waitForConfirmsOrDie(60000);
}
Also used : DefaultConsumer(com.rabbitmq.client.DefaultConsumer) Test(org.junit.Test)

Example 23 with DefaultConsumer

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

the class Confirm method basicRecover.

@Test
public void basicRecover() throws IOException, InterruptedException, TimeoutException {
    publishN("", "confirm-test-noconsumer", true, false);
    for (long i = 0; i < NUM_MESSAGES; i++) {
        GetResponse resp = channel.basicGet("confirm-test-noconsumer", false);
        resp.getEnvelope().getDeliveryTag();
    // not acking
    }
    channel.basicRecover(true);
    Thread.sleep(1000);
    channel.basicConsume("confirm-test-noconsumer", true, new DefaultConsumer(channel));
    channel.waitForConfirmsOrDie(60000);
}
Also used : DefaultConsumer(com.rabbitmq.client.DefaultConsumer) GetResponse(com.rabbitmq.client.GetResponse) Test(org.junit.Test)

Example 24 with DefaultConsumer

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

the class ConsumerPriorities method assertFailValidation.

private void assertFailValidation(Map<String, Object> args) throws IOException {
    Channel ch = connection.createChannel();
    String queue = ch.queueDeclare().getQueue();
    try {
        ch.basicConsume(queue, true, args, new DefaultConsumer(ch));
        fail("Validation should fail for " + args);
    } catch (IOException ioe) {
        checkShutdownSignal(AMQP.PRECONDITION_FAILED, ioe);
    }
}
Also used : DefaultConsumer(com.rabbitmq.client.DefaultConsumer) Channel(com.rabbitmq.client.Channel) IOException(java.io.IOException)

Example 25 with DefaultConsumer

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

the class QueueLease method expiresWithConsumers.

@Test
public void expiresWithConsumers() throws InterruptedException, IOException {
    Map<String, Object> args = new HashMap<String, Object>();
    args.put("x-expires", QUEUE_EXPIRES);
    channel.queueDeclare(TEST_EXPIRE_QUEUE, false, false, false, args);
    Consumer consumer = new DefaultConsumer(channel);
    String consumerTag = channel.basicConsume(TEST_EXPIRE_QUEUE, consumer);
    Thread.sleep(SHOULD_EXPIRE_WITHIN);
    try {
        channel.queueDeclarePassive(TEST_EXPIRE_QUEUE);
    } catch (IOException e) {
        checkShutdownSignal(AMQP.NOT_FOUND, e);
        fail("Queue expired before before passive re-declaration.");
    }
    channel.basicCancel(consumerTag);
    Thread.sleep(SHOULD_EXPIRE_WITHIN);
    try {
        channel.queueDeclarePassive(TEST_EXPIRE_QUEUE);
        fail("Queue should have been expired by now.");
    } catch (IOException e) {
        checkShutdownSignal(AMQP.NOT_FOUND, e);
    }
}
Also used : DefaultConsumer(com.rabbitmq.client.DefaultConsumer) Consumer(com.rabbitmq.client.Consumer) DefaultConsumer(com.rabbitmq.client.DefaultConsumer) HashMap(java.util.HashMap) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

DefaultConsumer (com.rabbitmq.client.DefaultConsumer)32 IOException (java.io.IOException)21 Envelope (com.rabbitmq.client.Envelope)20 Channel (com.rabbitmq.client.Channel)15 Test (org.junit.Test)15 AMQP (com.rabbitmq.client.AMQP)11 TimeoutException (java.util.concurrent.TimeoutException)10 Connection (com.rabbitmq.client.Connection)9 Consumer (com.rabbitmq.client.Consumer)9 ConnectionFactory (com.rabbitmq.client.ConnectionFactory)8 CountDownLatch (java.util.concurrent.CountDownLatch)4 BasicProperties (com.rabbitmq.client.AMQP.BasicProperties)3 AutorecoveringConnection (com.rabbitmq.client.impl.recovery.AutorecoveringConnection)3 KeyManagementException (java.security.KeyManagementException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 UUID (java.util.UUID)3 Path (javax.ws.rs.Path)3 AlreadyClosedException (com.rabbitmq.client.AlreadyClosedException)2 Recoverable (com.rabbitmq.client.Recoverable)2 RecoveryListener (com.rabbitmq.client.RecoveryListener)2