List of usage examples for org.springframework.amqp.rabbit.core RabbitAdmin getLastDeclarationExceptionEvent
public DeclarationExceptionEvent getLastDeclarationExceptionEvent()
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 . java 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()); }