Search in sources :

Example 36 with Message

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

the class TracingRabbitListenerAdviceTest method starts_new_trace_if_none_exists.

@Test
public void starts_new_trace_if_none_exists() throws Throwable {
    Message message = MessageBuilder.withBody(new byte[0]).build();
    onMessageConsumed(message);
    assertThat(spans).extracting(MutableSpan::kind).containsExactly(CONSUMER, null);
}
Also used : Message(org.springframework.amqp.core.Message) Test(org.junit.Test)

Example 37 with Message

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

the class TracingRabbitListenerAdviceTest method consumer_has_remote_service_name.

@Test
public void consumer_has_remote_service_name() throws Throwable {
    Message message = MessageBuilder.withBody(new byte[0]).build();
    onMessageConsumed(message);
    assertThat(spans).extracting(MutableSpan::remoteServiceName).containsExactly("my-exchange", null);
}
Also used : Message(org.springframework.amqp.core.Message) Test(org.junit.Test)

Example 38 with Message

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

the class TracingRabbitListenerAdviceTest method continues_parent_trace_single_header.

@Test
public void continues_parent_trace_single_header() throws Throwable {
    MessageProperties props = new MessageProperties();
    props.setHeader("b3", TRACE_ID + "-" + SPAN_ID + "-" + SAMPLED);
    Message message = MessageBuilder.withBody(new byte[0]).andProperties(props).build();
    onMessageConsumed(message);
    // cleared the headers to later work doesn't try to use the old parent
    assertThat(message.getMessageProperties().getHeaders()).isEmpty();
    assertThat(spans).filteredOn(span -> span.kind() == CONSUMER).extracting(MutableSpan::parentId).contains(SPAN_ID);
}
Also used : Message(org.springframework.amqp.core.Message) MessageProperties(org.springframework.amqp.core.MessageProperties) Test(org.junit.Test)

Example 39 with Message

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

the class TracingRabbitListenerAdviceTest method retains_baggage_headers.

@Test
public void retains_baggage_headers() throws Throwable {
    MessageProperties props = new MessageProperties();
    props.setHeader("b3", TRACE_ID + "-" + SPAN_ID + "-" + SAMPLED);
    props.setHeader(BAGGAGE_FIELD_KEY, "");
    Message message = MessageBuilder.withBody(new byte[0]).andProperties(props).build();
    onMessageConsumed(message);
    assertThat(message.getMessageProperties().getHeaders()).hasSize(// clears b3
    1).containsEntry(BAGGAGE_FIELD_KEY, "");
}
Also used : Message(org.springframework.amqp.core.Message) MessageProperties(org.springframework.amqp.core.MessageProperties) Test(org.junit.Test)

Example 40 with Message

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

the class TracingRabbitListenerAdviceTest method consumer_span_starts_before_listener.

@Test
public void consumer_span_starts_before_listener() throws Throwable {
    Message message = MessageBuilder.withBody(new byte[0]).build();
    onMessageConsumed(message);
    // make sure one before the other
    assertThat(spans.get(0).startTimestamp()).isLessThan(spans.get(1).startTimestamp());
    // make sure they finished
    assertThat(spans.get(0).finishTimestamp()).isPositive();
    assertThat(spans.get(1).finishTimestamp()).isPositive();
}
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