I am trying to send message using JmsSendingMessageHandler
but could not find a method which would fetch destination value from header something like messageHandler.setDestinationExpressionString("headers['destination_name']")
?
@MessagingGateway
public interface OutboundMessageGateway {
@Gateway(requestChannel = "outMessageChannel")
void sendMessage(Message<?> message);
}
@Bean
@ServiceActivator(inputChannel = "outMessageChannel" )
private MessageHandler jmsOutboundHandler() {
JmsSendingMessageHandler messageHandler = new JmsSendingMessageHandler(new JmsTemplate(connectionFactory());
messageHandler.setDestinationExpressionString("headers['destination_name']"); // not available
return messageHandler;
}
any solution ? I want to fetch destination dynamically from header I am passing with Message<?>
CodePudding user response:
There is no API like that JmsSendingMessageHandler.setDestinationExpressionString()
. Not sure why your IDE doesn't suggest you that you are on a wrong way, but there is other choice. My one shows this:
If you are really sure that you set that destination_name
upstream, then you indeed can use that setDestinationExpression(Expression)
API and like this:
handler.setDestinationExpression(new SpelExpressionParser().parseExpression("headers['destination_name']"));
Another, more Java-way is like this:
handler.setDestinationExpression(new FunctionExpression<Message<?>>(m -> m.getHeaders().get("destination_name")));
I think we can add that setDestinationExpressionString()
anyway, if you insist and can contribute such a fix back to the framework: https://github.com/spring-projects/spring-integration/blob/main/CONTRIBUTING.adoc