When I try to create a JMS session I am getting above mentioned error.Please advice.JMS server using is TIBCO. and I have tibjms.jar and jms.1.1 jars in class path.I am able to create connection. And spring-jms version is 4.1.4-Release version.
当我尝试创建一个JMS会话时,我将得到上面提到的错误。请建议。使用的JMS服务器是TIBCO。我有tibjms。jar和jms.1.1在类路径中发生了冲突。我能建立联系。spring-jms版本是4.1.4版本。
String reply = null;
QueueConnection connection = null;
QueueSession requestSession = null;
QueueSession replySession = null;
QueueReceiver receiver = null;
TemporaryQueue replyQueue = null;
try {
connection = (QueueConnection)jmsTemplate.createConnection();
connection.start();
requestSession = (QueueSession) jmsTemplate.createSession(connection);
replySession = (QueueSession) jmsTemplate.createSession(connection);
Queue queue = (Queue)jmsTemplate.getDestination(requestSession, jmsTemplate.getDefaultDestinationName());
replyQueue = replySession.createTemporaryQueue();
TextMessage requestMessage = requestSession.createTextMessage(message);
requestMessage.setJMSReplyTo(replyQueue);
LOGGER.debug("sending request/reply message "
+ jmsTemplate.getConnectionFactory()
+ requestMessage);
QueueSender queueSender = requestSession.createSender(queue);
queueSender.send(requestMessage);
receiver = replySession.createReceiver(replyQueue);
TextMessage replyMessage = (TextMessage)receiver.receive(jmsTemplate.getReceiveTimeout());
if(replyMessage != null){
reply = replyMessage.getText();
}
}catch(JMSException ex) {
1 个解决方案
#1
1
What did lead you to creating that abomination? Use the JmsTemplate
and JmsMessagingTemplate
instead.
是什么让你创造了这个令人厌恶的东西?使用JmsTemplate和JmsMessagingTemplate代替。
Replace your code with this
用这个替换代码
JmsMessagingTemplate jms = new JmsMessagingTemplate(jmsTemplate);
String reply = jms.convertSendAndReceive(message, String.class);
Or if you want to use a plain JmsTemplate
use the sendAndReceive
method, drawback is that you need to handle message creation and conversion yourself.
或者如果您想使用普通的JmsTemplate使用sendAndReceive方法,那么缺点是您需要自己处理消息创建和转换。
Message response = jmsTemplate.sendAndReceive(new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
return session.createTextMessage(message);
}
});
String reply = ((TextMessage) replyMessage).getText();
Either way everything is handled for you. You are using Spring then also take the benefit of that.
不管怎样,一切都是为你安排的。您正在使用Spring,然后也利用这个优势。
#1
1
What did lead you to creating that abomination? Use the JmsTemplate
and JmsMessagingTemplate
instead.
是什么让你创造了这个令人厌恶的东西?使用JmsTemplate和JmsMessagingTemplate代替。
Replace your code with this
用这个替换代码
JmsMessagingTemplate jms = new JmsMessagingTemplate(jmsTemplate);
String reply = jms.convertSendAndReceive(message, String.class);
Or if you want to use a plain JmsTemplate
use the sendAndReceive
method, drawback is that you need to handle message creation and conversion yourself.
或者如果您想使用普通的JmsTemplate使用sendAndReceive方法,那么缺点是您需要自己处理消息创建和转换。
Message response = jmsTemplate.sendAndReceive(new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
return session.createTextMessage(message);
}
});
String reply = ((TextMessage) replyMessage).getText();
Either way everything is handled for you. You are using Spring then also take the benefit of that.
不管怎样,一切都是为你安排的。您正在使用Spring,然后也利用这个优势。