从 Camel 路由强制对 ActiveMQ 的套接字超时? [英] Enforce socket timeout on ActiveMQ from Camel route?

查看:16
本文介绍了从 Camel 路由强制对 ActiveMQ 的套接字超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面我让 Camel(通过 Spring DSL)成功地将我的 bean 与 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>

我想在 Camel 和 ActiveMQ 之间明确强制执行 套接字超时(在 Socket.read() 上)- 25 秒.因此,当 Camel 尝试向/从 ActiveMQ 路由消息时,如果 ActiveMQ 需要超过 25 秒来完成该响应,我希望线程正常退出.显然,如果还可以设置某种故障转移(以便可以在将来重播超时的请求),这比仅仅丢失消息要好得多!

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!

更新:如果 Camel/JMS/ActiveMQ 不支持开箱即用,我不介意编写自己的ThreadManager"来中断/停止25 秒后线程,但我不确定要实现/扩展什么接口/类,以及随后连接到我的 Spring bean.

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 上设置 timeout 属性

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...

这篇关于从 Camel 路由强制对 ActiveMQ 的套接字超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆