Example usage for org.springframework.amqp.rabbit.core RabbitAdmin setIgnoreDeclarationExceptions

List of usage examples for org.springframework.amqp.rabbit.core RabbitAdmin setIgnoreDeclarationExceptions

Introduction

In this page you can find the example usage for org.springframework.amqp.rabbit.core RabbitAdmin setIgnoreDeclarationExceptions.

Prototype

public void setIgnoreDeclarationExceptions(boolean ignoreDeclarationExceptions) 

Source Link

Usage

From source file:cz.deii.sandbox.config.RabbitMqConfiguration.java

@Bean
public AmqpAdmin amqpAdmin() {
    RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory());
    rabbitAdmin.setIgnoreDeclarationExceptions(true); // useless
    return rabbitAdmin;
}

From source file:org.springframework.amqp.rabbit.core.RabbitAdminTests.java

@Test
public void testIgnoreDeclarationExeptionsTimeout() throws Exception {
    com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory = mock(
            com.rabbitmq.client.ConnectionFactory.class);
    TimeoutException toBeThrown = new TimeoutException("test");
    doThrow(toBeThrown).when(rabbitConnectionFactory).newConnection(any(ExecutorService.class), anyString());
    CachingConnectionFactory ccf = new CachingConnectionFactory(rabbitConnectionFactory);
    RabbitAdmin admin = new RabbitAdmin(ccf);
    List<DeclarationExceptionEvent> events = new ArrayList<DeclarationExceptionEvent>();
    admin.setApplicationEventPublisher(new EventPublisher(events));
    admin.setIgnoreDeclarationExceptions(true);
    admin.declareQueue(new AnonymousQueue());
    admin.declareQueue();/*from w  w w  .ja  v  a 2  s  .c o  m*/
    admin.declareExchange(new DirectExchange("foo"));
    admin.declareBinding(new Binding("foo", DestinationType.QUEUE, "bar", "baz", null));
    assertThat(events.size(), equalTo(4));
    assertThat(events.get(0).getSource(), sameInstance(admin));
    assertThat(events.get(0).getDeclarable(), instanceOf(AnonymousQueue.class));
    assertSame(toBeThrown, events.get(0).getThrowable().getCause());
    assertNull(events.get(1).getDeclarable());
    assertSame(toBeThrown, events.get(1).getThrowable().getCause());
    assertThat(events.get(2).getDeclarable(), instanceOf(DirectExchange.class));
    assertSame(toBeThrown, events.get(2).getThrowable().getCause());
    assertThat(events.get(3).getDeclarable(), instanceOf(Binding.class));
    assertSame(toBeThrown, events.get(3).getThrowable().getCause());

    assertSame(events.get(3), admin.getLastDeclarationExceptionEvent());
}