本文介绍了ActiveMQ:如何在使用临时队列时处理代理故障转移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的JMS应用程序上,我们在Producers上使用临时队列,以便能够从消费者应用程序接收回复。

On my JMS applications we use temporary queues on Producers to be able to receive replies back from Consumer applications.

我面临的问题与我提到的完全相同在这个帖子中:

I am facing exactly same issue on my end as mentioned in this thread: http://activemq.2283324.n4.nabble.com/jira-Created-AMQ-3336-Temporary-Destination-errors-on-H-A-failover-in-broker-network-with-Failover-tt-td3551034.html#a3612738

每当我在网络中重新启动任意代理时,我就会得到尝试将回复发送到临时队列时,我的消费者应用程序日志中出现了许多这样的错误:

Whenever I restarted an arbitrary broker in my network, I was getting many errors like this in my Consumer application log while trying to send reply to a temporary queue:

javax.jms.InvalidDestinationException:
  Cannot publish to a deleted Destination: temp-queue://ID:...

然后我看到Gary在那里建议使用

Then I saw Gary's response there suggesting to use

jms.watchTopicAdvisories=false

作为网址参数客户端 brokerURL 。我使用此附加参数立即更改了客户端代理URL。但是现在,当我在网络中重新启动我的代理以进行此故障转移测试时,我发现这样的错误:

as a url param on the client brokerURL. I promptly changed my client broker URLs with this additional parameter. However now I am seeing errors like this when I restart my brokers in network for this failover testing:

javax.jms.JMSException: 
  The destination temp-queue:
    //ID:client.host-65070-1308610734958-2:1:1 does not exist.

我使用的是ActiveMQ 5.5版本。我的客户端代理URL如下所示:

I am using ActiveMQ 5.5 version. And my client broker URL looks like this:

failover:(tcp://amq-host1:61616,tcp://amq-host2.tred.aol.com:61616,tcp://amq-host3:61616,tcp://amq-host4:61616)?jms.useAsyncSend=true&timeout=5000&jms.watchTopicAdvisories=false

此外,这是我的4个经纪人之一的activemq配置XML:

Additionally here is my activemq config XML for one of the 4 brokers:amq1.xml

有人可以在这里查看这个问题并建议我在这个设置中犯了什么错误。

Can someone here please look into this problem and suggest me what mistake I am making in this setup.

进一步澄清我在代码中如何进行请求 - 响应:

To clarify further on how I am doing request-response in my code:


  1. 我已经使用了每个生产者目的地(即临时队列)并将其设置在每条消息的回复标题中。

  2. 我已经在JMSCorrelationID标头中发送了每条消息唯一的相关标识符。

  3. 据我所知,即使Camel和Spring也使用临时队列进行请求 - 响应机制。唯一的区别是Spring JMS实现为每条消息创建和销毁临时队列,而我在生产者的生命周期中创建临时队列。当客户端(生产者)应用程序关闭时,或者当AMQ代理意识到没有与此临时队列连接的活动生成器时,此临时队列将被销毁。

  4. 我已经设置了消息到期时间生产者方面的每条消息,以便消息不会在队列中停留太长时间(60秒)。

  1. I already use a per producer destination (i.e. temporary queue) and set this in reply-to header of every message.
  2. I am already sending a per message unique correlation identifier in JMSCorrelationID header.
  3. As far as I know even Camel and Spring are also using temporary queue for request-response mechanism. Only difference is that Spring JMS implementation creates and destroys temporary queue for every message whereas I create temporary queue for the lifetime of the producer. This temporary queue is destroyed when client (producer) app shutsdown or by the AMQ broker when it realizes there are no active producer attached with this temporary queue.
  4. I am already setting a message expiry on each message on Producer side so that message is not held up in a queue for too long (60 sec).


推荐答案

有一个代理属性,org.apache.activemq.broker.BrokerService #cacheTempDestinations应该有助于故障转移:case。
在xml配置中将其设置为true,并且在客户端断开连接时不会立即删除临时目标。
快速故障转移:重新连接将能够再次从临时队列中生成和/或使用。

There is a broker attribute, org.apache.activemq.broker.BrokerService#cacheTempDestinations that should help in the failover: case. Set that to true in xml configuration, and a temp destination will not be removed immediately when a client disconnects. A fast failover: reconnect will be able to producer and/or consume from the temp queue again.

有一个基于timeBeforePurgeTempDestinations(默认为5秒)的计时器任务来处理缓存删除。

There is a timer task based on timeBeforePurgeTempDestinations (default 5 seconds) that handles cache removal.

一个警告但是,我没有在activemq-core中看到任何使用该属性的测试,因此我无法对此提供任何保证。

One caveat though, I don't see any tests in activemq-core that make use of that attribute so I can't give you any guarantee on this one.

这篇关于ActiveMQ:如何在使用临时队列时处理代理故障转移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 08:19