Search in sources :

Example 6 with Message

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));
}
Also used : RabbitTemplate(org.springframework.amqp.rabbit.core.RabbitTemplate) Message(org.springframework.amqp.core.Message) Test(org.junit.Test)

Example 7 with Message

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);
}
Also used : Message(org.springframework.amqp.core.Message)

Example 8 with Message

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);
}
Also used : RetryTemplate(org.springframework.retry.support.RetryTemplate) MessageRecoverer(org.springframework.amqp.rabbit.retry.MessageRecoverer) Message(org.springframework.amqp.core.Message) ExponentialBackOffPolicy(org.springframework.retry.backoff.ExponentialBackOffPolicy) MethodInvocationRecoverer(org.springframework.retry.interceptor.MethodInvocationRecoverer) SimpleRetryPolicy(org.springframework.retry.policy.SimpleRetryPolicy) Advice(org.aopalliance.aop.Advice) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException)

Example 9 with Message

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();
}
Also used : Message(org.springframework.amqp.core.Message) Test(org.junit.Test)

Example 10 with Message

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$");
}
Also used : Message(org.springframework.amqp.core.Message) Test(org.junit.Test)

Aggregations

Message (org.springframework.amqp.core.Message)43 Test (org.junit.Test)38 MessageProperties (org.springframework.amqp.core.MessageProperties)15 ConnectionFactory (org.springframework.amqp.rabbit.connection.ConnectionFactory)6 RabbitTemplate (org.springframework.amqp.rabbit.core.RabbitTemplate)6 AbstractMessageListenerContainer (org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer)5 ChannelAwareMessageListener (org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener)5 QueueChannel (org.springframework.integration.channel.QueueChannel)5 BeanFactory (org.springframework.beans.factory.BeanFactory)4 AmqpInboundChannelAdapter (org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter)4 GenericMessage (org.springframework.messaging.support.GenericMessage)4 AsyncRabbitTemplate (org.springframework.amqp.rabbit.AsyncRabbitTemplate)3 SimpleMessageListenerContainer (org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer)3 Channel (com.rabbitmq.client.Channel)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Advice (org.aopalliance.aop.Advice)2 AmqpTemplate (org.springframework.amqp.core.AmqpTemplate)2 MessageListener (org.springframework.amqp.core.MessageListener)2 Connection (org.springframework.amqp.rabbit.connection.Connection)2 MessageRecoverer (org.springframework.amqp.rabbit.retry.MessageRecoverer)2