Websphere MQ JMSTemplate 设置 ReplyTo
Websphere MQ JMSTemplate setting ReplyTo
我正在尝试使用 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_QUEUE
和 TEST_QUEUE
。
设法做到了:
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;
}
});
setJMSReplyTo
方法采用 javax.jms.Destination
类型的对象。您将需要创建一个 javax.jms.Destination
class 的实例。您可以创建临时队列或永久队列。
Destination replyToQ = session.createQueue("REPLYQ");
TextMessage message = session.createTextMessage();
message.setJMSReplyTo(replyToQ);
return message;
我正在尝试使用 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_QUEUE
和 TEST_QUEUE
。
设法做到了:
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;
}
});
setJMSReplyTo
方法采用 javax.jms.Destination
类型的对象。您将需要创建一个 javax.jms.Destination
class 的实例。您可以创建临时队列或永久队列。
Destination replyToQ = session.createQueue("REPLYQ");
TextMessage message = session.createTextMessage();
message.setJMSReplyTo(replyToQ);
return message;