use of org.springframework.amqp.core.Message in project spring-integration by spring-projects.
the class OutboundEndpointTests method testAsyncDelayExpression.
@Test
public void testAsyncDelayExpression() {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
AsyncRabbitTemplate amqpTemplate = spy(new AsyncRabbitTemplate(new RabbitTemplate(connectionFactory), new SimpleMessageListenerContainer(connectionFactory), "replyTo"));
amqpTemplate.setTaskScheduler(mock(TaskScheduler.class));
AsyncAmqpOutboundGateway gateway = new AsyncAmqpOutboundGateway(amqpTemplate);
willAnswer(invocation -> amqpTemplate.new RabbitMessageFuture("foo", invocation.getArgument(2))).given(amqpTemplate).sendAndReceive(anyString(), anyString(), any(Message.class));
gateway.setExchangeName("foo");
gateway.setRoutingKey("bar");
gateway.setDelayExpressionString("42");
gateway.setBeanFactory(mock(BeanFactory.class));
gateway.setOutputChannel(new NullChannel());
gateway.afterPropertiesSet();
gateway.start();
ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
gateway.handleMessage(new GenericMessage<>("foo"));
verify(amqpTemplate).sendAndReceive(eq("foo"), eq("bar"), captor.capture());
assertThat(captor.getValue().getMessageProperties().getDelay(), equalTo(42));
}
use of org.springframework.amqp.core.Message in project spring-integration by spring-projects.
the class OutboundEndpointTests method testHeaderMapperWinsAdapter.
@Test
public void testHeaderMapperWinsAdapter() {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
RabbitTemplate amqpTemplate = spy(new RabbitTemplate(connectionFactory));
AmqpOutboundEndpoint endpoint = new AmqpOutboundEndpoint(amqpTemplate);
endpoint.setHeadersMappedLast(true);
final AtomicReference<Message> amqpMessage = new AtomicReference<Message>();
willAnswer(invocation -> {
amqpMessage.set(invocation.getArgument(2));
return null;
}).given(amqpTemplate).send(isNull(), isNull(), any(Message.class), isNull());
org.springframework.messaging.Message<?> message = MessageBuilder.withPayload("foo").setHeader(MessageHeaders.CONTENT_TYPE, "bar").build();
endpoint.handleMessage(message);
assertNotNull(amqpMessage.get());
assertEquals("bar", amqpMessage.get().getMessageProperties().getContentType());
}
use of org.springframework.amqp.core.Message in project spring-integration by spring-projects.
the class DefaultAmqpHeaderMapperTests method jsonTypeIdNotOverwritten.
// INT-2090
@Test
public void jsonTypeIdNotOverwritten() {
DefaultAmqpHeaderMapper headerMapper = DefaultAmqpHeaderMapper.inboundMapper();
MessageConverter converter = new Jackson2JsonMessageConverter();
MessageProperties amqpProperties = new MessageProperties();
converter.toMessage("123", amqpProperties);
Map<String, Object> headerMap = new HashMap<String, Object>();
headerMap.put("__TypeId__", "java.lang.Integer");
MessageHeaders integrationHeaders = new MessageHeaders(headerMap);
headerMapper.fromHeadersToRequest(integrationHeaders, amqpProperties);
assertEquals("java.lang.String", amqpProperties.getHeaders().get("__TypeId__"));
Object result = converter.fromMessage(new Message("123".getBytes(), amqpProperties));
assertEquals(String.class, result.getClass());
}
use of org.springframework.amqp.core.Message in project av-service by dvoraka.
the class AvMessageMapper method transform.
/**
* Transforms AV message to AMQP message.
*
* @param msg the AV message
* @return the AMQP message
* @throws MapperException if mapping failed
*/
public Message transform(AvMessage msg) throws MapperException {
log.debug("AVTransform: " + msg);
requireNonNull(msg, "Message must not be null!");
// mandatory fields
if (msg.getId() == null) {
throw new MapperException("Message ID must not be null");
} else if (msg.getType() == null) {
throw new MapperException("Message type must not be null");
}
MessageProperties props = new MessageProperties();
props.setMessageId(msg.getId());
props.setType(msg.getType().toString());
// correlation ID
if (msg.getCorrelationId() != null) {
props.setCorrelationId(msg.getCorrelationId());
}
// virus info
props.setHeader(VIRUS_INFO_KEY, msg.getVirusInfo());
// owner
props.setHeader(OWNER_KEY, msg.getOwner());
// filename
props.setHeader(FILENAME_KEY, msg.getFilename());
return new Message(msg.getData(), props);
}
use of org.springframework.amqp.core.Message in project brave by openzipkin.
the class MessageHeadersTest method setHeader_noProperties.
@Test
public void setHeader_noProperties() {
message = new Message(new byte[0], null);
// doesn't crash
MessageHeaders.setHeader(message, "b3", "1");
}
Aggregations