Search code examples
spring-bootspring-integrationspring-jms

Is there a way to send message with MQSTR format using JmsSendingMessageHandler


I am using JmsSendingMessageHandler to send JMS message

@Bean
@ServiceActivator(inputChannel = "queueChannel" )
public MessageHandler sendMessageOnTopic() {

    JmsSendingMessageHandler messageHandler = new JmsSendingMessageHandler(jmsTemplate);
    messageHandler.setDestinationExpression(new FunctionExpression<Message<?>>(message -> message.getHeaders().get("destination")));
    return messageHandler;

}

by default messages goes to MQ with format MQHRF2. problem with that is mainframe only understands MQSTR format,

Is there a way I can do it with some configuration or adding any headers (I tried adding JMS_IBM_Format to MQSTR as message header but did not work) ?

I am able to achieve the same if I use jmsTemplate directly like below

jmsTemplate.convertAndSend("queue:///" + message.getHeaders().get("destination") + "?targetClient=1", message.getPayload());

I was wondering if I can achieve the same results with JmsSendingMessageHandler ?


Solution

  • As @Artem mentioned in the comments, this can be done as

    @Bean
    @ServiceActivator(inputChannel = "queueChannel" )
    public MessageHandler sendMessageOnTopic() {
    
        JmsSendingMessageHandler messageHandler = new JmsSendingMessageHandler(jmsTemplate);
        messageHandler.setDestinationExpression(new FunctionExpression<Message<?>>(message -> "queue:///" + message.getHeaders().get("destination") + "?targetClient=1"));
        return messageHandler;
    
    }
    

    or even if we pass the destination as queue:///QUEUE_NAME?targetClient=1 directly from yml.