Search in sources :

Example 31 with Message

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

the class TracingMessagePostProcessorTest method should_resume_headers.

@Test
public void should_resume_headers() {
    Message message = MessageBuilder.withBody(new byte[0]).build();
    message.getMessageProperties().setHeader("b3", B3SingleFormat.writeB3SingleFormat(parent));
    Message postProcessMessage = tracingMessagePostProcessor.postProcessMessage(message);
    assertThat(spans.get(0).parentId()).isEqualTo(parent.spanIdString());
    Map<String, Object> headers = postProcessMessage.getMessageProperties().getHeaders();
    assertThat(headers.get("b3").toString()).endsWith("-" + spans.get(0).id() + "-1");
}
Also used : Message(org.springframework.amqp.core.Message) Test(org.junit.Test)

Example 32 with Message

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

the class TracingMessagePostProcessorTest method should_prefer_current_span.

@Test
public void should_prefer_current_span() {
    // Will be either a bug, or a missing processor stage which can result in an old span in headers
    Message message = MessageBuilder.withBody(new byte[0]).build();
    message.getMessageProperties().setHeader("b3", B3SingleFormat.writeB3SingleFormat(grandparent));
    Message postProcessMessage;
    try (Scope scope = tracing.currentTraceContext().newScope(parent)) {
        postProcessMessage = tracingMessagePostProcessor.postProcessMessage(message);
    }
    assertThat(spans.get(0).parentId()).isEqualTo(parent.spanIdString());
    Map<String, Object> headers = postProcessMessage.getMessageProperties().getHeaders();
    assertThat(headers.get("b3").toString()).endsWith("-" + spans.get(0).id() + "-1");
}
Also used : Message(org.springframework.amqp.core.Message) Scope(brave.propagation.CurrentTraceContext.Scope) Test(org.junit.Test)

Example 33 with Message

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

the class TracingMessagePostProcessorTest method should_report_span.

@Test
public void should_report_span() {
    Message message = MessageBuilder.withBody(new byte[0]).build();
    tracingMessagePostProcessor.postProcessMessage(message);
    assertThat(spans).hasSize(1);
}
Also used : Message(org.springframework.amqp.core.Message) Test(org.junit.Test)

Example 34 with Message

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

the class TracingMessagePostProcessorTest method should_retain_baggage.

@Test
public void should_retain_baggage() {
    Message message = MessageBuilder.withBody(new byte[0]).build();
    message.getMessageProperties().setHeader("b3", B3SingleFormat.writeB3SingleFormat(parent));
    message.getMessageProperties().setHeader(BAGGAGE_FIELD_KEY, "");
    Message postProcessMessage = tracingMessagePostProcessor.postProcessMessage(message);
    assertThat(spans.get(0).parentId()).isEqualTo(parent.spanIdString());
    Map<String, Object> headers = postProcessMessage.getMessageProperties().getHeaders();
    assertThat(headers.get("b3").toString()).endsWith("-" + spans.get(0).id() + "-1");
    assertThat(headers.get(BAGGAGE_FIELD_KEY).toString()).isEmpty();
}
Also used : Message(org.springframework.amqp.core.Message) Test(org.junit.Test)

Example 35 with Message

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

the class TracingRabbitListenerAdviceTest method consumer_and_listener_have_names.

@Test
public void consumer_and_listener_have_names() throws Throwable {
    Message message = MessageBuilder.withBody(new byte[0]).build();
    onMessageConsumed(message);
    assertThat(spans).extracting(MutableSpan::name).containsExactly("next-message", "on-message");
}
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