The below code shows how I am setting header and message type to AMQP message.
MessageProperties properties = new MessageProperties();
properties.setHeader("KEY", "HOUSE");
properties.setContentType(MessageProperties.CONTENT_TYPE_JSON);
Message message = new Message("1234567;Branch A;SALES;3000.50;Pending approval".getBytes(), properties);
rabbitTemplate.sendAndReceive("", QUEUE_NAME, message);
After sending the message in the queue, the message is received by Transformer.
@Transformer(inputChannel = "inboundChannel", outputChannel = "toutboundChannel")
public Property buildProperty(Message<String> property){
LOGGER.info("message received :: HEADERS: {}, PAYLOAD :{}", property.getHeaders(), property.getPayload());
....
}
In the logs, the header "KEY: HOUSE" is missing and even the message type is not JSON and "text/plain" instead.
LOGS:
[SimpleAsyncTaskExecutor-1] INFO com.demo.maven.spring.integration.endpoint.TransformerRequestBuilder - message received :: HEADERS: {amqp_receivedRoutingKey=mobile.queue, amqp_deliveryTag=2, amqp_replyTo=amq.rabbitmq.reply-to.g2dkABByYWJiaXRAbG9jYWxob3N0AAAW9QAAAAAD.tTIFOS2gsM7qIlGYaybfrg==, amqp_deliveryMode=PERSISTENT, amqp_redelivered=true, id=399dda4f-4ba1-7cf4-2310-03dbfbac82b6, contentType=text/plain, timestamp=1421649922840}, PAYLOAD :1234567;Branch A;SALES;3000.50;Pending approval
MessagePropertiesBuilder
class is for that.
By default Spring Integration AMQP Inbound Endpoint (AmqpInboundChannelAdapter
and AmqpInboundGateway
) maps only standard AMQP headers. That's is a default behaviour of DefaultAmqpHeaderMapper
. To accept any user-specofic headers you should inject AmqpHeaderMapper
(setHeaderMapper
) to that inbound endpoint with an option setRequestHeaderNames("*")
. Or provide full list of names of desired custom headers.
Re. contentType=text/plain
: I think something between AMQP Inbound Endpoint and that @Transformer(inputChannel = "inboundChannel"
overrides the received from AMQP contentType
header. Because RabbitTemplate
doesn't do that, if you send Message
not any other Object. Please, share DEBUG
logs for the org.springframework.integration
category for the message receiver. Of course we need that part of logs, when you receive message till that @Transformer
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments