use of org.springframework.amqp.core.Message in project brave by openzipkin.
the class TracingRabbitListenerAdviceTest method continues_parent_trace.
@Test
public void continues_parent_trace() 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();
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);
}
use of org.springframework.amqp.core.Message in project brave by openzipkin.
the class TracingRabbitListenerAdviceTest method tags_consumer_span_but_not_listener.
@Test
public void tags_consumer_span_but_not_listener() throws Throwable {
MessageProperties properties = new MessageProperties();
properties.setConsumerQueue("foo");
Message message = MessageBuilder.withBody(new byte[0]).andProperties(properties).build();
onMessageConsumed(message);
assertThat(spans.get(0).tags()).containsExactly(entry("rabbit.queue", "foo"));
assertThat(spans.get(1).tags()).isEmpty();
}
use of org.springframework.amqp.core.Message in project spring-boot by spring-projects.
the class RabbitAutoConfigurationTests method testRabbitListenerContainerFactoryWithCustomSettings.
@Test
public void testRabbitListenerContainerFactoryWithCustomSettings() {
load(new Class<?>[] { MessageConvertersConfiguration.class, MessageRecoverersConfiguration.class }, "spring.rabbitmq.listener.retry.enabled:true", "spring.rabbitmq.listener.retry.maxAttempts:4", "spring.rabbitmq.listener.retry.initialInterval:2000", "spring.rabbitmq.listener.retry.multiplier:1.5", "spring.rabbitmq.listener.retry.maxInterval:5000", "spring.rabbitmq.listener.autoStartup:false", "spring.rabbitmq.listener.acknowledgeMode:manual", "spring.rabbitmq.listener.concurrency:5", "spring.rabbitmq.listener.maxConcurrency:10", "spring.rabbitmq.listener.prefetch:40", "spring.rabbitmq.listener.defaultRequeueRejected:false", "spring.rabbitmq.listener.idleEventInterval:5", "spring.rabbitmq.listener.transactionSize:20");
SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = this.context.getBean("rabbitListenerContainerFactory", SimpleRabbitListenerContainerFactory.class);
DirectFieldAccessor dfa = new DirectFieldAccessor(rabbitListenerContainerFactory);
assertThat(dfa.getPropertyValue("autoStartup")).isEqualTo(Boolean.FALSE);
assertThat(dfa.getPropertyValue("acknowledgeMode")).isEqualTo(AcknowledgeMode.MANUAL);
assertThat(dfa.getPropertyValue("concurrentConsumers")).isEqualTo(5);
assertThat(dfa.getPropertyValue("maxConcurrentConsumers")).isEqualTo(10);
assertThat(dfa.getPropertyValue("prefetchCount")).isEqualTo(40);
assertThat(dfa.getPropertyValue("txSize")).isEqualTo(20);
assertThat(dfa.getPropertyValue("messageConverter")).isSameAs(this.context.getBean("myMessageConverter"));
assertThat(dfa.getPropertyValue("defaultRequeueRejected")).isEqualTo(Boolean.FALSE);
assertThat(dfa.getPropertyValue("idleEventInterval")).isEqualTo(5L);
Advice[] adviceChain = (Advice[]) dfa.getPropertyValue("adviceChain");
assertThat(adviceChain).isNotNull();
assertThat(adviceChain.length).isEqualTo(1);
dfa = new DirectFieldAccessor(adviceChain[0]);
MessageRecoverer messageRecoverer = this.context.getBean("myMessageRecoverer", MessageRecoverer.class);
MethodInvocationRecoverer<?> mir = (MethodInvocationRecoverer<?>) dfa.getPropertyValue("recoverer");
Message message = mock(Message.class);
Exception ex = new Exception("test");
mir.recover(new Object[] { "foo", message }, ex);
verify(messageRecoverer).recover(message, ex);
RetryTemplate retryTemplate = (RetryTemplate) dfa.getPropertyValue("retryOperations");
assertThat(retryTemplate).isNotNull();
dfa = new DirectFieldAccessor(retryTemplate);
SimpleRetryPolicy retryPolicy = (SimpleRetryPolicy) dfa.getPropertyValue("retryPolicy");
ExponentialBackOffPolicy backOffPolicy = (ExponentialBackOffPolicy) dfa.getPropertyValue("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 TracingRabbitListenerAdviceTest method consumer_has_service_name.
@Test
public void consumer_has_service_name() throws Throwable {
Message message = MessageBuilder.withBody(new byte[] {}).build();
onMessageConsumed(message);
assertThat(reportedSpans).extracting(Span::remoteServiceName).containsExactly("my-service", null);
}
use of org.springframework.amqp.core.Message in project spring-integration by spring-projects.
the class DispatcherHasNoSubscribersTests method testPubSub.
@Test
public void testPubSub() {
final Channel channel = mock(Channel.class);
Connection connection = mock(Connection.class);
doAnswer(invocation -> channel).when(connection).createChannel(anyBoolean());
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
when(connectionFactory.createConnection()).thenReturn(connection);
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
AmqpTemplate amqpTemplate = mock(AmqpTemplate.class);
PublishSubscribeAmqpChannel amqpChannel = new PublishSubscribeAmqpChannel("noSubscribersChannel", container, amqpTemplate);
amqpChannel.setBeanName("noSubscribersChannel");
amqpChannel.setBeanFactory(mock(BeanFactory.class));
amqpChannel.afterPropertiesSet();
List<String> logList = insertMockLoggerInListener(amqpChannel);
MessageListener listener = (MessageListener) container.getMessageListener();
listener.onMessage(new Message("Hello world!".getBytes(), null));
verifyLogReceived(logList);
}
Aggregations