How to remove default Spring JMS Template headers when sending a message to an MQ?

冷暖自知 提交于 2020-06-16 08:51:37

问题


Using Java/Spring to interact with a WebSphere MQ and trying to send a message to it, Spring keeps adding the following header information to it:

RFH Ì ¸MQSTR ¸ <mcd><Msd>jms_text</Msd></mcd> <jms><Dst>queue:///MY.QUEUE.INFORMATION.TEST</Dst><Rto>queue:///MY.QUEUE.INFORMATION.TEST</Rto><Tms>123456789</Tms><Dlv>2</Dlv></jms>BEGINNING_OF_MY_PAYLOAD

How would I remove everything and only send my payload? One could refer to my payload in the snippet above as BEGINNING_OF_MY_PAYLOAD.

Here's the function I'm using:

public void sendMessage(final String text) {
        this.jmsTemplate.send(new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                Message message = session.createTextMessage(text);
                destination = session.createQueue("MY.QUEUE.INFORMATION.TEST");
                springJmsConsumer.setDestination(destination);
                message.setJMSReplyTo(destination);
                return message;
            }
        });
    }

回答1:


Figured it out. Anytime we want to remove headers from our Spring JMS message being sent out to a WebSphere MQ, always use the following:

this.jmsTemplate.convertAndSend("queue:///YOUR.QUEUE.NAME.HERE?targetClient=1", text);

So now my function looks like:

public void send(String text) {
        this.jmsTemplate.convertAndSend("queue:///MY.QUEUE.INFORMATION.TEST?targetClient=1", text);
}


来源:https://stackoverflow.com/questions/38877048/how-to-remove-default-spring-jms-template-headers-when-sending-a-message-to-an-m

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!