Search in sources :

Example 11 with Message

use of org.springframework.amqp.core.Message in project brave by openzipkin.

the class TracingMessagePostProcessorTest method should_set_remote_service.

@Test
public void should_set_remote_service() {
    Message message = MessageBuilder.withBody(new byte[0]).build();
    tracingMessagePostProcessor.postProcessMessage(message);
    assertThat(spans.get(0).remoteServiceName()).isEqualTo("my-exchange");
}
Also used : Message(org.springframework.amqp.core.Message) Test(org.junit.Test)

Example 12 with Message

use of org.springframework.amqp.core.Message in project brave by openzipkin.

the class TracingRabbitListenerAdviceTest method reports_span_if_consume_fails.

@Test
public void reports_span_if_consume_fails() throws Throwable {
    Message message = MessageBuilder.withBody(new byte[0]).build();
    RuntimeException error = new RuntimeException("Test exception");
    onMessageConsumeFailed(message, error);
    assertThat(spans).extracting(MutableSpan::kind).containsExactly(CONSUMER, null);
    assertThat(spans).filteredOn(span -> span.kind() == null).extracting(MutableSpan::error).containsExactly(error);
}
Also used : Message(org.springframework.amqp.core.Message) Test(org.junit.Test)

Example 13 with Message

use of org.springframework.amqp.core.Message in project brave by openzipkin.

the class TracingRabbitListenerAdviceTest method reports_span_if_consume_fails_with_no_message.

@Test
public void reports_span_if_consume_fails_with_no_message() throws Throwable {
    Message message = MessageBuilder.withBody(new byte[0]).build();
    RuntimeException error = new RuntimeException("Test exception");
    onMessageConsumeFailed(message, error);
    assertThat(spans).extracting(MutableSpan::kind).containsExactly(CONSUMER, null);
    assertThat(spans).filteredOn(span -> span.kind() == null).extracting(MutableSpan::error).containsExactly(error);
}
Also used : Message(org.springframework.amqp.core.Message) Test(org.junit.Test)

Example 14 with Message

use of org.springframework.amqp.core.Message in project brave by openzipkin.

the class TracingRabbitListenerAdviceTest method batch_new_trace_last_traced.

@Test
public void batch_new_trace_last_traced() throws Throwable {
    MessageProperties props = new MessageProperties();
    props.setHeader("X-B3-TraceId", TRACE_ID_2);
    props.setHeader("X-B3-SpanId", SPAN_ID_2);
    props.setHeader("X-B3-ParentSpanId", PARENT_ID_2);
    props.setHeader("X-B3-Sampled", SAMPLED);
    Message message = MessageBuilder.withBody(new byte[0]).build();
    Message message2 = MessageBuilder.withBody(new byte[0]).andProperties(props).build();
    onBatchMessageConsumed(Arrays.asList(message, message2));
    // new trace
    assertThat(spans.get(0)).extracting(MutableSpan::parentId).isNotEqualTo(SPAN_ID);
}
Also used : Message(org.springframework.amqp.core.Message) MessageProperties(org.springframework.amqp.core.MessageProperties) Test(org.junit.Test)

Example 15 with Message

use of org.springframework.amqp.core.Message in project brave by openzipkin.

the class TracingRabbitListenerAdviceTest method batch_continue_first_traced.

@Test
public void batch_continue_first_traced() throws Throwable {
    MessageProperties props = new MessageProperties();
    props.setHeader("X-B3-TraceId", TRACE_ID);
    props.setHeader("X-B3-SpanId", SPAN_ID);
    props.setHeader("X-B3-ParentSpanId", PARENT_ID);
    props.setHeader("X-B3-Sampled", SAMPLED);
    Message message = MessageBuilder.withBody(new byte[0]).andProperties(props).build();
    Message message2 = MessageBuilder.withBody(new byte[0]).build();
    onBatchMessageConsumed(Arrays.asList(message, message2));
    // cleared the headers to later work doesn't try to use the old parent
    assertThat(message.getMessageProperties().getHeaders()).isEmpty();
    // first traced that listener continues that trace
    assertThat(spans.get(0)).extracting(MutableSpan::parentId).isEqualTo(SPAN_ID);
}
Also used : Message(org.springframework.amqp.core.Message) MessageProperties(org.springframework.amqp.core.MessageProperties) 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