Enforce socket timeout on ActiveMQ from Camel route?(从 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 timeout(在 Socket.read()
上)为 25 秒.因此,当 Camel 尝试将消息路由到 ActiveMQ 或从 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 上的套接字超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 Camel 路由强制 ActiveMQ 上的套接字超时?


- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01