从骆驼航线强制套接字超时上的ActiveMQ? [英] Enforce socket timeout on ActiveMQ from Camel route?
问题描述
所以,下面我有骆驼(通过Spring DSL)成功整合我的豆子和ActiveMQ队列:
So below I have Camel (via Spring DSL) successfully integrating my beans with ActiveMQ queues:
<!-- Note: this code is just a snippet; if you need to see more, please let me know! -->
<camelContext id="my-camel-context" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="activemq-myinstance:queue:myqueue" />
<onException>
<exception>java.lang.Exception</exception>
<redeliveryPolicy maximumRedeliveries="2" />
<to uri="activemq-myinstance:queue_failures" />
</onException>
<to uri="bean:myBean?method=doCommand" />
</route>
</camelContext>
<bean id="jmsConnectionFactory-myqueue" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="${activemq.instance.url}" />
</bean>
<bean id="pooledConnectionFactory-myqueue" class="org.apache.activemq.pool.PooledConnectionFactory">
<property name="maxConnections" value="64" />
<property name="maximumActive" value="${max.active.consumers}" />
<property name="connectionFactory" ref="jmsConnectionFactory-myqueue" />
</bean>
<bean id="jmsConfig-myqueue" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="pooledConnectionFactory-myqueue"/>
<property name="concurrentConsumers" value="${max.active.consumers}"/>
</bean>
<bean id="activemq-myqueue" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="jmsConfig-myqueue"/>
</bean>
我想明确强制执行的套接字超时(适用于 Socket.read()
) - 25秒 - 骆驼和之间的ActiveMQ 。因此,到/从ActiveMQ的,如果ActiveMQ的花费超过25秒的时间完成该响应,我想在骆驼试图将消息路由线程正常退出。显然,如果有可能还设置了某种故障转移(这样的超时时间可以在将来某个时间得到重播请求),这是极大的preferred在刚刚失去了消息!
I'd like to explicitly enforce a socket timeout (on Socket.read()
) - between Camel and ActiveMQ - of 25 seconds. Thus, when Camel attempts to route a message to/from ActiveMQ, if ActiveMQ takes more than 25 seconds to complete that response, I want the thread to exit gracefully. Obviously, if it's possible to also set up some kind of failover (so that requests that timeout can get replayed at a future time) that is greatly preferred over just losing the message!
我怎样才能做到这一点?在此先感谢!
How can I accomplish this? Thanks in advance!
更新:如果骆驼/ JMS / ActiveMQ的不支持此开箱,我不介意写我自己的 ThreadManager
可中断25秒后/停止线程,但我不知道要实现什么样的接口/类/扩展,并随后丝进入我的Spring beans。
Update: if Camel/JMS/ActiveMQ doesn't support this out of the box, I don't mind writing my own "ThreadManager
" that interrupts/stops threads after 25-seconds, but I'm not sure what interface/classes to implement/extend, and to subsequently wire into my Spring beans.
推荐答案
刚刚设置的暂停
您brokerURL财产
just set the timeout
property on your brokerURL
failover:(tcp\://localhost\:61616)?timeout=25000
这将传播错误返回到您的制片人,所以你可以处理它而不是它只是阻塞线程永远...的
this will propagate an error back to your producer so you can handle it instead of having it just blocking the thread forever...
这篇关于从骆驼航线强制套接字超时上的ActiveMQ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!