javax.jms.InvalidDestinationException:无法使用另一个连接的临时目标

发布于 2024-11-29 04:18:03 字数 885 浏览 0 评论 0原文

我有一个生产者,它连接到 ActiveMQ 代理以向客户端发送消息。

  1. 由于它期望来自客户端的一些响应,因此它首先创建一个临时队列并将其与 JMS 回复 标头相关联。
  2. 然后,它将消息发送到代理并等待临时队列上来自客户端的响应。
  3. 通过临时队列接收客户端的响应,执行所需的操作,然后退出。

大多数情况下这工作正常,但应用程序偶尔会抛出错误消息,指出“无法使用从另一个连接创建的队列”。

我无法确定什么可能导致这种情况发生,因为临时队列是从当前会话本身创建的。

有其他人遇到过这种情况并知道如何解决吗?

代码片段:

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.

  1. Since it expects some response from the client, it first creates a temp queue and associates it to the JMS replyto header.
  2. It then sends the message over to the broker and waits for the response on temp queue from the client.
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

儭儭莪哋寶赑 2024-12-06 04:18:03

如果您有一个客户端尝试作为使用者订阅由不同连接实例创建的临时目标,您会收到类似的错误。 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文