Search in sources :

Example 1 with StrictExceptionHandler

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

the class StrictExceptionHandlerTest method tooLongClosingMessage.

@Test
public void tooLongClosingMessage() throws Exception {
    ConnectionFactory cf = TestUtils.connectionFactory();
    final CountDownLatch latch = new CountDownLatch(1);
    cf.setExceptionHandler(new StrictExceptionHandler() {

        @Override
        public void handleConsumerException(Channel channel, Throwable exception, Consumer consumer, String consumerTag, String methodName) {
            try {
                super.handleConsumerException(channel, exception, consumer, consumerTag, methodName);
            } catch (IllegalArgumentException e) {
                fail("No exception should caught");
            }
            latch.countDown();
        }
    });
    try (Connection c = cf.newConnection()) {
        Channel channel = c.createChannel();
        String queue = channel.queueDeclare().getQueue();
        channel.basicConsume(queue, new VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClassName(channel));
        channel.basicPublish("", queue, null, new byte[0]);
        assertThat(latch.await(5, TimeUnit.SECONDS)).isTrue();
    }
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) DefaultConsumer(com.rabbitmq.client.DefaultConsumer) Consumer(com.rabbitmq.client.Consumer) Channel(com.rabbitmq.client.Channel) StrictExceptionHandler(com.rabbitmq.client.impl.StrictExceptionHandler) Connection(com.rabbitmq.client.Connection) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

Channel (com.rabbitmq.client.Channel)1 Connection (com.rabbitmq.client.Connection)1 ConnectionFactory (com.rabbitmq.client.ConnectionFactory)1 Consumer (com.rabbitmq.client.Consumer)1 DefaultConsumer (com.rabbitmq.client.DefaultConsumer)1 StrictExceptionHandler (com.rabbitmq.client.impl.StrictExceptionHandler)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1