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 上的套接字超时?


基础教程推荐
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 降序排序:Java Map 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01