use of org.springframework.amqp.core.Message in project brave by openzipkin.
the class TracingMessagePostProcessorTest method should_add_b3_headers_to_message.
@Test
public void should_add_b3_headers_to_message() {
Message message = MessageBuilder.withBody(new byte[] {}).build();
Message postProcessMessage = tracingMessagePostProcessor.postProcessMessage(message);
List<String> expectedHeaders = Arrays.asList("X-B3-TraceId", "X-B3-SpanId", "X-B3-Sampled");
Set<String> headerKeys = postProcessMessage.getMessageProperties().getHeaders().keySet();
assertThat(headerKeys).containsAll(expectedHeaders);
}
use of org.springframework.amqp.core.Message in project microservices by pwillhan.
the class RabbitTemplateExample method main.
public static void main(String[] args) throws UnsupportedEncodingException {
CachingConnectionFactory factory = null;
try {
factory = new CachingConnectionFactory("localhost");
RabbitTemplate template = new RabbitTemplate(factory);
MessageProperties properties = new MessageProperties();
properties.setContentType("text/xml");
properties.setContentEncoding("utf-8");
String soapMessage = "<soapenv:Envelope" + "xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope\">\n" + "<soapenv:Header/>\n" + "<soapenv:Body>\n" + " <p:greet xmlns:p=\"http://greet.service.kishanthan.org\">\n" + " <in>" + "sample" + "</in>\n" + " </p:greet>\n" + "</soapenv:Body>\n" + "</soapenv:Envelope>";
Message message = new Message(soapMessage.getBytes("UTF-8"), properties);
template.convertAndSend("", "test-queue", message);
} finally {
if (factory != null) {
factory.destroy();
}
}
}
use of org.springframework.amqp.core.Message in project spring-integration by spring-projects.
the class OutboundEndpointTests method testDelayExpression.
@Test
public void testDelayExpression() {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
RabbitTemplate amqpTemplate = spy(new RabbitTemplate(connectionFactory));
AmqpOutboundEndpoint endpoint = new AmqpOutboundEndpoint(amqpTemplate);
willDoNothing().given(amqpTemplate).send(anyString(), anyString(), any(Message.class), isNull());
willAnswer(invocation -> invocation.getArgument(2)).given(amqpTemplate).sendAndReceive(anyString(), anyString(), any(Message.class), isNull());
endpoint.setExchangeName("foo");
endpoint.setRoutingKey("bar");
endpoint.setDelayExpressionString("42");
endpoint.setBeanFactory(mock(BeanFactory.class));
endpoint.afterPropertiesSet();
endpoint.handleMessage(new GenericMessage<>("foo"));
ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
verify(amqpTemplate).send(eq("foo"), eq("bar"), captor.capture(), isNull());
assertThat(captor.getValue().getMessageProperties().getDelay(), equalTo(42));
endpoint.setExpectReply(true);
endpoint.setOutputChannel(new NullChannel());
endpoint.handleMessage(new GenericMessage<>("foo"));
verify(amqpTemplate).sendAndReceive(eq("foo"), eq("bar"), captor.capture(), isNull());
assertThat(captor.getValue().getMessageProperties().getDelay(), equalTo(42));
endpoint.setDelay(23);
endpoint.setRoutingKey("baz");
endpoint.afterPropertiesSet();
endpoint.handleMessage(new GenericMessage<>("foo"));
verify(amqpTemplate).sendAndReceive(eq("foo"), eq("baz"), captor.capture(), isNull());
assertThat(captor.getValue().getMessageProperties().getDelay(), equalTo(23));
}
use of org.springframework.amqp.core.Message in project spring-integration by spring-projects.
the class OutboundEndpointTests method testHeaderMapperWinsGateway.
@Test
public void testHeaderMapperWinsGateway() {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
TestRabbitTemplate amqpTemplate = spy(new TestRabbitTemplate(connectionFactory));
AmqpOutboundEndpoint endpoint = new AmqpOutboundEndpoint(amqpTemplate);
endpoint.setHeadersMappedLast(true);
endpoint.setExpectReply(true);
DefaultAmqpHeaderMapper mapper = DefaultAmqpHeaderMapper.inboundMapper();
mapper.setRequestHeaderNames("*");
endpoint.setHeaderMapper(mapper);
final AtomicReference<Message> amqpMessage = new AtomicReference<Message>();
willAnswer(invocation -> {
amqpMessage.set(invocation.getArgument(2));
return null;
}).given(amqpTemplate).doSendAndReceiveWithTemporary(isNull(), isNull(), any(Message.class), isNull());
org.springframework.messaging.Message<?> message = MessageBuilder.withPayload("foo").setHeader(MessageHeaders.CONTENT_TYPE, "bar").setReplyChannel(new QueueChannel()).build();
endpoint.handleMessage(message);
assertNotNull(amqpMessage.get());
assertEquals("bar", amqpMessage.get().getMessageProperties().getContentType());
assertNull(amqpMessage.get().getMessageProperties().getHeaders().get(MessageHeaders.REPLY_CHANNEL));
}
use of org.springframework.amqp.core.Message in project spring-integration by spring-projects.
the class AmqpInboundChannelAdapterParserTests method withHeaderMapperOnlyCustomHeaders.
@Test
public void withHeaderMapperOnlyCustomHeaders() throws Exception {
AmqpInboundChannelAdapter adapter = context.getBean("withHeaderMapperOnlyCustomHeaders", AmqpInboundChannelAdapter.class);
AbstractMessageListenerContainer mlc = TestUtils.getPropertyValue(adapter, "messageListenerContainer", AbstractMessageListenerContainer.class);
ChannelAwareMessageListener listener = TestUtils.getPropertyValue(mlc, "messageListener", ChannelAwareMessageListener.class);
MessageProperties amqpProperties = new MessageProperties();
amqpProperties.setAppId("test.appId");
amqpProperties.setClusterId("test.clusterId");
amqpProperties.setContentEncoding("test.contentEncoding");
amqpProperties.setContentLength(99L);
amqpProperties.setContentType("test.contentType");
amqpProperties.setHeader("foo", "foo");
amqpProperties.setHeader("bar", "bar");
Message amqpMessage = new Message("hello".getBytes(), amqpProperties);
listener.onMessage(amqpMessage, null);
QueueChannel requestChannel = context.getBean("requestChannel", QueueChannel.class);
org.springframework.messaging.Message<?> siMessage = requestChannel.receive(0);
assertEquals("foo", siMessage.getHeaders().get("foo"));
assertNull(siMessage.getHeaders().get("bar"));
assertNull(siMessage.getHeaders().get(AmqpHeaders.CONTENT_ENCODING));
assertNull(siMessage.getHeaders().get(AmqpHeaders.CLUSTER_ID));
assertNull(siMessage.getHeaders().get(AmqpHeaders.APP_ID));
assertNull(siMessage.getHeaders().get(AmqpHeaders.CONTENT_TYPE));
}
Aggregations