AsyncRabbitTemplate asyncTemplate = new AsyncRabbitTemplate(template, container); asyncTemplate.setEnableConfirms(true); asyncTemplate.setMandatory(true);
@Test @DirtiesContext public void testReturn() throws Exception { this.asyncTemplate.setMandatory(true); ListenableFuture<String> future = this.asyncTemplate.convertSendAndReceive(this.requests.getName() + "x", "foo"); try { future.get(10, TimeUnit.SECONDS); fail("Expected exception"); } catch (ExecutionException e) { assertThat(e.getCause(), instanceOf(AmqpMessageReturnedException.class)); assertEquals(this.requests.getName() + "x", ((AmqpMessageReturnedException) e.getCause()).getRoutingKey()); } }
@Test @DirtiesContext public void testReturnDirect() throws Exception { this.asyncDirectTemplate.setMandatory(true); ListenableFuture<String> future = this.asyncDirectTemplate.convertSendAndReceive(this.requests.getName() + "x", "foo"); try { future.get(10, TimeUnit.SECONDS); fail("Expected exception"); } catch (ExecutionException e) { assertThat(e.getCause(), instanceOf(AmqpMessageReturnedException.class)); assertEquals(this.requests.getName() + "x", ((AmqpMessageReturnedException) e.getCause()).getRoutingKey()); } }