Have an incoming message from ActiveMQ queue and the message is being delivered properly. I need to access the JMS header value x-cutoffrule
in my spring integration flow, but the value of cutoffrule
in the handle section always is coming as null. My code is below:
@Bean
public JmsHeaderMapper sampleJmsHeaderMapper() {
return new DefaultJmsHeaderMapper() {
public Map<String, Object> toHeaders(javax.jms.Message jmsMessage) {
Map<String, Object> headers = super.toHeaders(jmsMessage);
try {
headers.put("cutoffrule", jmsMessage.getStringProperty("x-cutoffrule"));
} catch (JMSException e) {
e.printStackTrace();
}
return headers;
}
};
}
@Bean
public IntegrationFlow jmsMessageDrivenFlow(JmsHeaderMapper sampleJmsHeaderMapper ) {
return IntegrationFlows
.from(
Jms.messageDriverChannelAdapter(jmsMessagingTemplate.getConnectionFactory())
.destination(integrationProps.getIncomingRequestQueue())
.errorChannel(errorChannel())
.setHeaderMapper( sampleJmsHeaderMapper )
)
.handle((payload, headers) -> {
incomingPayload = payload;
logger.debug("cutoffrule"+ headers.get("cutoffrule"));
return payload;
})
.handle(message -> {
logger.debug("Message was succcessfully processed");
})
.get();
}
I thought the DefaultJmsHeaderMapper
will map all JMS headers into the spring integration message. What am I missing?
sampleJmsHeaderMapper
? Why don't use "x-cutoffrule" inside your(payload, headers) -> {...}
handler? – Andriy Kryvtsunx-cutoffrule
property... Please, debug your for confirmation. When we found the property, you will be able to map it into the appropriate header from your customtoHeaders()
– Artem BilanJmsHeaderMapper
, extract your handler as a separate class as a successor ofAbstractMessageProcessingTransformer
and change call fromhandle
totransform
in your chain. And in your successedtransform
method check presents of your field inMessage<?> message
parameter. – Andriy Kryvtsunmessage
param hasorg.springframework.messaging.Message
type withgetPayload
andgetHeaders
methods. – Andriy Kryvtsun