Search in sources :

Example 1 with DefaultExceptionHandler

use of com.rabbitmq.client.impl.DefaultExceptionHandler in project rabbitmq-java-client by rabbitmq.

the class CloseInMainLoop method specialConnectionFactory.

private ConnectionFactory specialConnectionFactory() {
    ConnectionFactory f = TestUtils.connectionFactory();
    f.setExceptionHandler(new DefaultExceptionHandler() {

        @Override
        public void handleConsumerException(Channel channel, Throwable exception, Consumer consumer, String consumerTag, String methodName) {
            try {
                // TODO: change this to call 4-parameter close and make 6-parm one private
                ((AMQConnection) channel.getConnection()).close(AMQP.INTERNAL_ERROR, "Internal error in Consumer " + consumerTag, false, exception, -1, false);
            } catch (Throwable e) {
            // Man, this clearly isn't our day.
            // TODO: Log the nested failure
            } finally {
                closeLatch.countDown();
            }
        }
    });
    return f;
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) DefaultConsumer(com.rabbitmq.client.DefaultConsumer) Consumer(com.rabbitmq.client.Consumer) Channel(com.rabbitmq.client.Channel) DefaultExceptionHandler(com.rabbitmq.client.impl.DefaultExceptionHandler)

Example 2 with DefaultExceptionHandler

use of com.rabbitmq.client.impl.DefaultExceptionHandler in project rabbitmq-java-client by rabbitmq.

the class ExceptionHandling method defaultConsumerHandleConsumerException.

@Test
public void defaultConsumerHandleConsumerException() throws IOException, InterruptedException, TimeoutException {
    final CountDownLatch latch = new CountDownLatch(1);
    final ExceptionHandler eh = new DefaultExceptionHandler() {

        @Override
        public void handleConsumerException(Channel channel, Throwable exception, Consumer consumer, String consumerTag, String methodName) {
            super.handleConsumerException(channel, exception, consumer, consumerTag, methodName);
            latch.countDown();
        }
    };
    testConsumerHandleConsumerException(eh, latch, true);
}
Also used : DefaultExceptionHandler(com.rabbitmq.client.impl.DefaultExceptionHandler) ForgivingExceptionHandler(com.rabbitmq.client.impl.ForgivingExceptionHandler) ExceptionHandler(com.rabbitmq.client.ExceptionHandler) DefaultConsumer(com.rabbitmq.client.DefaultConsumer) Consumer(com.rabbitmq.client.Consumer) Channel(com.rabbitmq.client.Channel) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultExceptionHandler(com.rabbitmq.client.impl.DefaultExceptionHandler) Test(org.junit.Test)

Aggregations

Channel (com.rabbitmq.client.Channel)2 Consumer (com.rabbitmq.client.Consumer)2 DefaultConsumer (com.rabbitmq.client.DefaultConsumer)2 DefaultExceptionHandler (com.rabbitmq.client.impl.DefaultExceptionHandler)2 ConnectionFactory (com.rabbitmq.client.ConnectionFactory)1 ExceptionHandler (com.rabbitmq.client.ExceptionHandler)1 ForgivingExceptionHandler (com.rabbitmq.client.impl.ForgivingExceptionHandler)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1