所以下面我有骆驼(通过 Spring DSL)成功地将我的 bean 与 ActiveMQ 队列集成:
<!-- 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 之间显式地强制执行 25 秒的套接字超时(on )。Socket.read()
因此,当 Camel 尝试将消息路由到 ActiveMQ 或从 ActiveMQ 路由消息时,如果 ActiveMQ 需要超过 25 秒才能完成该响应,我希望线程优雅地退出。显然,如果还可以设置某种故障转移(以便超时的请求可以在未来重播),这比仅仅丢失消息更可取!
我怎样才能做到这一点?提前致谢!
更新:如果 Camel/JMS/ActiveMQ 不支持这个开箱即用,我不介意编写自己的“ ThreadManager
”,在 25 秒后中断/停止线程,但我不确定要实现哪些接口/类/extend,然后连接到我的 Spring bean。