2017-02-21 75 views
0

我有一个与activemq代理交互的spring JMS应用程序。如果应用程序无法访问代理,则无限期地重试。我如何配置我的DefaultJmsListenerContainerFactory bean中的activemq.xml文件或so​​emthing,以便它不会无限期地重试?如何限制activemq实例上的重新连接数

我看到一个ActiveMQ的ReconnectionPolicy引用,但我不知道如何在activemq.xml中获取设置,或者如果它可以在JMS容器出厂设置

回答

1

设置在监听器容器工厂BackOff

/** 
* Specify the {@link BackOff} instance to use to compute the interval 
* between recovery attempts. If the {@link BackOffExecution} implementation 
* returns {@link BackOffExecution#STOP}, this listener container will not further 
* attempt to recover. 
* <p>The {@link #setRecoveryInterval(long) recovery interval} is ignored 
* when this property is set. 
* @since 4.1 
*/ 

ExponentialBackOff将增加次尝试之间,定制BackOff可以返回BackOffExecution.STOP和容器将stop()本身。 FixedBackOff可以配置为maxAttempts

您也可以在容器注册表(或从注册表中使用其id获得的单个容器)上调用stop()

1

在DefaultJmsListenerContainerFactory水平,你可以设置像这样:

  FixedBackOff fbo = new FixedBackOff(); // or ExponentialBackOff 
      fbo.setMaxAttempts(10); 
      fbo.setInterval(5000); 
      DefaultJmsListenerContainerFactory djlcf = new DefaultJmsListenerContainerFactory(); 
      djlcf.setBackOff(fbo); 

org.springframework.jms.listener.DefaultMessageListenerContainer.setBackOff(BackOff)

UPDATE

你只能通过更改

的URL使用FailoverTransport
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("failover:(tcp://host:61617)?maxReconn‌​ectAttempts=10"); 

看看activemq.apache.org/failover-transport-reference.html

+0

谢谢。有没有办法在服务器级别设置适用于所有客户端的方式,或者这是按客户端设置设置的吗? –

+0

这是一个弹簧配置和行为,它不受AMQ配置的影响......最好在客户端设置 –

+0

也许如果你想要最简单的设置,你可以使用'FailoverTransport'只能通过改变' ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(“failover:(tcp:// host:61617)?maxReconnectAttempts = Value”)'看看http://activemq.apache.org/failover-transport-reference.html –