Websphere MQ JMSTemplate设置ReplyTo

时间:2015-07-01 13:44:41

标签: java spring jms ibm-mq

我尝试将带有replyTo属性的消息发送到WebSphere MQ。

@SpringBootApplication
public class WmqSenderApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext ctx = SpringApplication.run(WmqSenderApplication.class, args);
        JmsTemplate jmsTemplate = ctx.getBean(JmsTemplate.class);
        jmsTemplate.send("TEST_QUEUE",new MessageCreator() {

            @Override
            public Message createMessage(Session session) throws JMSException {
                TextMessage message = session.createTextMessage();
                message.setJMSReplyTo(new MQDestination("REPLY_QUEUE"));//com.ibm.mq.jms.MQDestination
                return message;
            }
        });

    }

    @Bean
    public MQQueueConnectionFactory connFac() throws JMSException {
        MQQueueConnectionFactory cf = new MQQueueConnectionFactory();
        cf.setTransportType(1);
        cf.setHostName("localhost");
        cf.setPort(1417);
        cf.setQueueManager("TEST");
        cf.setChannel("CHANNEL");
        return cf;
    }
    @Bean
    public JmsTemplate jmsTemplate() throws JMSException {
        return new JmsTemplate(connFac());
    }
}

但我得到了:

com.ibm.msg.client.jms.DetailedInvalidDestinationException: 
JMSCMQ0005: The destination name '://REPLY_QUEUE' was not valid. The destination name specified does not conform to published destination syntax. Correct the specified destination name and try again.

我在经纪人中创建了REPLY_QUEUETEST_QUEUE

2 个答案:

答案 0 :(得分:2)

setJMSReplyTo方法采用javax.jms.Destination类型的对象。您需要创建javax.jms.Destination类的实例。您可以创建临时队列或永久队列。

     Destination replyToQ = session.createQueue("REPLYQ");
     TextMessage message = session.createTextMessage();
     message.setJMSReplyTo(replyToQ);
     return message;

答案 1 :(得分:0)

管理:

jmsTemplate.send("TEST_QUEUE",new MessageCreator() {

            @Override
            public Message createMessage(Session session) throws JMSException {
                TextMessage message = session.createTextMessage();
                Queue queue = session.createQueue("REPLY_QUEUE");
                message.setJMSReplyTo(queue);
                return message;
            }
        });