ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class); verify(amqpTemplate).send(eq("foo"), eq("bar"), captor.capture(), isNull()); assertThat(captor.getValue().getMessageProperties().getDelay(), equalTo(42)); endpoint.setExpectReply(true); endpoint.setOutputChannel(new NullChannel()); endpoint.handleMessage(new GenericMessage<>("foo")); verify(amqpTemplate).sendAndReceive(eq("foo"), eq("bar"), captor.capture(), isNull()); assertThat(captor.getValue().getMessageProperties().getDelay(), equalTo(42)); endpoint.handleMessage(new GenericMessage<>("foo")); verify(amqpTemplate).sendAndReceive(eq("foo"), eq("baz"), captor.capture(), isNull()); assertThat(captor.getValue().getMessageProperties().getDelay(), equalTo(23));
@Test public void testAsyncDelayExpression() { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); AsyncRabbitTemplate amqpTemplate = spy(new AsyncRabbitTemplate(new RabbitTemplate(connectionFactory), new SimpleMessageListenerContainer(connectionFactory), "replyTo")); amqpTemplate.setTaskScheduler(mock(TaskScheduler.class)); AsyncAmqpOutboundGateway gateway = new AsyncAmqpOutboundGateway(amqpTemplate); willAnswer( invocation -> amqpTemplate.new RabbitMessageFuture("foo", invocation.getArgument(2))) .given(amqpTemplate).sendAndReceive(anyString(), anyString(), any(Message.class)); gateway.setExchangeName("foo"); gateway.setRoutingKey("bar"); gateway.setDelayExpressionString("42"); gateway.setBeanFactory(mock(BeanFactory.class)); gateway.setOutputChannel(new NullChannel()); gateway.afterPropertiesSet(); gateway.start(); ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class); gateway.handleMessage(new GenericMessage<>("foo")); verify(amqpTemplate).sendAndReceive(eq("foo"), eq("bar"), captor.capture()); assertThat(captor.getValue().getMessageProperties().getDelay(), equalTo(42)); }
assertEquals("test.contentType", amqpProperties.getContentType()); assertEquals(testCorrelationId, amqpProperties.getCorrelationId()); assertEquals(Integer.valueOf(1234), amqpProperties.getDelay()); assertEquals(MessageDeliveryMode.NON_PERSISTENT, amqpProperties.getDeliveryMode()); assertEquals(1234L, amqpProperties.getDeliveryTag());
assertEquals("test.type", amqpProperties.getType()); assertEquals("test.userId", amqpProperties.getUserId()); assertEquals(Integer.valueOf(1234), amqpProperties.getDelay());