use of org.springframework.amqp.core.Message in project spring-integration by spring-projects.
the class AmqpMessageSourceIntegrationTests method testImplicitNackThenAck.
@Test
public void testImplicitNackThenAck() throws Exception {
RabbitTemplate template = new RabbitTemplate(this.config.connectionFactory());
template.convertAndSend(QUEUE_WITH_DLQ, "foo");
template.convertAndSend(QUEUE_WITH_DLQ, "nackIt");
template.convertAndSend(DSL_QUEUE, "bar");
template.convertAndSend(INTERCEPT_QUEUE, "baz");
template.convertAndSend(NOAUTOACK_QUEUE, "qux");
assertTrue(this.config.latch.await(10, TimeUnit.SECONDS));
assertThat(this.config.received, equalTo("foo"));
Message dead = template.receive(DLQ, 10_000);
assertNotNull(dead);
assertThat(this.config.fromDsl, equalTo("bar"));
assertThat(this.config.fromInterceptedSource, equalTo("BAZ"));
assertNull(template.receive(NOAUTOACK_QUEUE));
assertThat(this.config.requeueLatch.getCount(), equalTo(1L));
this.config.callback.acknowledge(Status.REQUEUE);
assertTrue(this.config.requeueLatch.await(10, TimeUnit.SECONDS));
}
use of org.springframework.amqp.core.Message in project pinpoint by naver.
the class TestReceiver_Pre_1_6_0 method receiveMessage.
@Override
public <T> T receiveMessage(String queueName, MessageConverter<T> messageConverter) {
Message message = rabbitTemplate.receive(queueName);
if (message == null) {
return null;
}
byte[] body = message.getBody();
return messageConverter.convertMessage(body);
}
use of org.springframework.amqp.core.Message in project spring-boot by spring-projects.
the class RabbitAutoConfigurationTests method checkCommonProps.
private void checkCommonProps(AssertableApplicationContext context, AbstractRabbitListenerContainerFactory<?> containerFactory) {
assertThat(containerFactory).hasFieldOrPropertyWithValue("autoStartup", Boolean.FALSE);
assertThat(containerFactory).hasFieldOrPropertyWithValue("acknowledgeMode", AcknowledgeMode.MANUAL);
assertThat(containerFactory).hasFieldOrPropertyWithValue("prefetchCount", 40);
assertThat(containerFactory).hasFieldOrPropertyWithValue("messageConverter", context.getBean("myMessageConverter"));
assertThat(containerFactory).hasFieldOrPropertyWithValue("defaultRequeueRejected", Boolean.FALSE);
assertThat(containerFactory).hasFieldOrPropertyWithValue("idleEventInterval", 5L);
Advice[] adviceChain = containerFactory.getAdviceChain();
assertThat(adviceChain).isNotNull();
assertThat(adviceChain).hasSize(1);
Advice advice = adviceChain[0];
MessageRecoverer messageRecoverer = context.getBean("myMessageRecoverer", MessageRecoverer.class);
MethodInvocationRecoverer<?> mir = (MethodInvocationRecoverer<?>) ReflectionTestUtils.getField(advice, "recoverer");
Message message = mock(Message.class);
Exception ex = new Exception("test");
mir.recover(new Object[] { "foo", message }, ex);
then(messageRecoverer).should().recover(message, ex);
RetryTemplate retryTemplate = (RetryTemplate) ReflectionTestUtils.getField(advice, "retryOperations");
assertThat(retryTemplate).isNotNull();
SimpleRetryPolicy retryPolicy = (SimpleRetryPolicy) ReflectionTestUtils.getField(retryTemplate, "retryPolicy");
ExponentialBackOffPolicy backOffPolicy = (ExponentialBackOffPolicy) ReflectionTestUtils.getField(retryTemplate, "backOffPolicy");
assertThat(retryPolicy.getMaxAttempts()).isEqualTo(4);
assertThat(backOffPolicy.getInitialInterval()).isEqualTo(2000);
assertThat(backOffPolicy.getMultiplier()).isEqualTo(1.5);
assertThat(backOffPolicy.getMaxInterval()).isEqualTo(5000);
}
use of org.springframework.amqp.core.Message in project brave by openzipkin.
the class MessageHeadersTest method getHeaderIfString_noProperties.
@Test
public void getHeaderIfString_noProperties() {
message = new Message(new byte[0], null);
assertThat(MessageHeaders.getHeaderIfString(message, "b3")).isNull();
}
use of org.springframework.amqp.core.Message in project brave by openzipkin.
the class TracingMessagePostProcessorTest method should_add_b3_single_header_to_message.
@Test
public void should_add_b3_single_header_to_message() {
Message message = MessageBuilder.withBody(new byte[0]).build();
Message postProcessMessage = tracingMessagePostProcessor.postProcessMessage(message);
assertThat(postProcessMessage.getMessageProperties().getHeaders()).containsOnlyKeys("b3");
assertThat(postProcessMessage.getMessageProperties().getHeaders().get("b3").toString()).matches("^[0-9a-f]{16}-[0-9a-f]{16}-1$");
}
Aggregations