javax.jms.InvalidDestinationException:无法使用另一个连接的临时目标
我有一个生产者,它连接到 ActiveMQ 代理以向客户端发送消息。
- 由于它期望来自客户端的一些响应,因此它首先创建一个临时队列并将其与 JMS 回复 标头相关联。
- 然后,它将消息发送到代理并等待临时队列上来自客户端的响应。
- 通过临时队列接收客户端的响应,执行所需的操作,然后退出。
大多数情况下这工作正常,但应用程序偶尔会抛出错误消息,指出“无法使用从另一个连接创建的队列”。
我无法确定什么可能导致这种情况发生,因为临时队列是从当前会话本身创建的。
有其他人遇到过这种情况并知道如何解决吗?
代码片段:
Connection conn = myJmsTemp. getConnectionFactory().createConnection();
ses = conn.createSession(transacted,ackMode);
responseQueue = ses.createTemporaryQueue();
...
MyMessageCreator msgCrtr = new MyMessageCreator(objects,responseQueue);
myJmsTemp.send(dest, msgCrtr);
myJmsTemp.setReceiveTimeout(timeout);
ObjectMessage response = (ObjectMessage)myJmsTemplate.receive(responseQueue);
这里MyMessageCreator
实现了MessageCreator
接口。
我要做的就是向代理发送消息并通过临时队列等待客户端的响应。我还使用池连接工厂来获取连接。
I have a producer which connects to ActiveMQ broker to send me messages to the client.
- Since it expects some response from the client, it first creates a temp queue and associates it to the JMS replyto header.
- It then sends the message over to the broker and waits for the response on temp queue from the client.
- Receives the response from the client over the temp queue, performs required actions and then exits.
This works fine most of the times, but sporadically the application throws error messsages saying " Cannot use queue created from another connection ".
I am unable to identify what could cause this to happen as the temp queue is being created from the current session itself.
Did anyone else come across this situation and knows how to fix it?
Code snippet:
Connection conn = myJmsTemp. getConnectionFactory().createConnection();
ses = conn.createSession(transacted,ackMode);
responseQueue = ses.createTemporaryQueue();
...
MyMessageCreator msgCrtr = new MyMessageCreator(objects,responseQueue);
myJmsTemp.send(dest, msgCrtr);
myJmsTemp.setReceiveTimeout(timeout);
ObjectMessage response = (ObjectMessage)myJmsTemplate.receive(responseQueue);
Here MyMessageCreator
implements MessageCreator
interface.
All am trying to do is send a message to the broker and wait for a response from the client over the temp queue. Also am using a pooled connection factory to get the connection.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有一个客户端尝试作为使用者订阅由不同连接实例创建的临时目标,您会收到类似的错误。 JMS 规范定义只有创建临时目标的连接才能使用它,因此这就是存在限制的原因。至于您看到它的原因,如果没有看到遇到错误的代码,就很难说。
鉴于您的更新表明您正在使用池连接工厂,我猜这是您问题的根源。如果消耗调用碰巧使用池中的连接与创建临时目标的连接不同,那么您将看到您提到的错误。
You get an error like this if you have a client that is trying to subscribe as a consumer on a temporary destination that was created by a different connection instance. The JMS spec defines that only the connection that created the temp destination can consume from it, so that's why the limitation exists. As for the reason you are seeing it its hard to say without seeing your code that encounters the error.
Given that your update says you are using the Pooled connection factory I'd guess that this is the root of you issue. If the consume call happens to use a different connection from the Pool than the one that created the temp destination then you would see the error that you mentioned.