Apache的骆驼 - JMS INONLY行为时,经纪人下来(Apache Camel - JM

2019-10-18 12:22发布

我生产与骆驼的ActiveMQ组件的ActiveMQ的实例:

<camel:log message="YMA_IN" />
<camel:inOnly uri="activemqBroker:queue:queue.test" id="activemqBrokerTestQueue"/>
<camel:log message="YMA_OUT" />

在端点上唯一的JMS配置是TTL和连接池工厂。

<amq:connectionFactory id="jmsConnectionFactory" brokerURL="${config.jms.broker.url}" />

<bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory" init-method="start" destroy-method="stop">
    <property name="maxConnections" value="15" />
    <property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>

<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
    <property name="connectionFactory" ref="pooledConnectionFactory"/>
    <property name="timeToLive" value="${config.jms.time.to.live}" />
</bean>

<!-- Broker configuration -->
<bean id="activemqBroker" class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="configuration" ref="jmsConfig"/>
</bean>  

如果代理下来,交流仍然停留在INONLY(IN但不是OUT登录),貌似无限期,直到经纪人备份。 也不例外,没有超时等..

这是预期的行为,如果经纪人是跌? 我期待一个例外? 是否有一些配置我失踪?

骆驼2.10.1

Answer 1:

也有选择使用同步发送,那么客户端会检测到错误越早(而不必等待超时),并能够抛出骆驼可以检测异常。 看到一些细节,在

  • http://activemq.apache.org/connection-configuration-uri.html
  • http://activemq.apache.org/async-sends.html


Answer 2:

事实上,这似乎是预期的行为:超时必须在代理URL本身配置。

以下的答案必须说明如何进行配置:

https://stackoverflow.com/a/15416704/609452

随后的的JMSException一个简单的try / catch工作



Answer 3:

有了这个配置我的骆驼一次ActiveMQ代理下降到失败的消息:

    ActiveMQConnectionFactory mqConnectionFactory = new ActiveMQConnectionFactory();
    mqConnectionFactory.setUseAsyncSend(true);
    mqConnectionFactory.setCloseTimeout(closeTimeout);
    mqConnectionFactory.setBrokerURL(brokerUrl);
    mqConnectionFactory.setUserName(userName);
    mqConnectionFactory.setPassword(password());

    PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory();
    pooledConnectionFactory.setMaxConnections(maxConnections);
    pooledConnectionFactory.setConnectionFactory(mqConnectionFactory);

    JmsConfiguration jmsConfiguration = new JmsConfiguration();
    jmsConfiguration.setConnectionFactory(pooledConnectionFactory);
    jmsConfiguration.setTransacted(false);

    ActiveMQComponent amqComponent = new ActiveMQComponent();
    amqComponent.setConfiguration(jmsConfiguration);


文章来源: Apache Camel - JMS inonly behaviour when broker down