我遇到问题实际上是在Camel和ActiveMQ中发生超时异常。我有以下路线设置:
public void configure() throws Exception {
from("activemq:queue:test.queue")
.transacted()
.beanRef("testMessageHandler", "handle");
}
我有以下CamelContext设置:
CamelGuiceRegistry rego = new CamelGuiceRegistry(injector);
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(connectionString);
connectionFactory.setUserName("user");
connectionFactory.setPassword("password");
PlatformTransactionManager transactionManager = injector.getInstance(Key.get(PlatformTransactionManager.class, Names.named("transactionManager")));
JmsComponent jmsCom = JmsComponent.jmsComponentTransacted(connectionFactory, transactionManager);
jmsCom.setTransactionTimeout(1);
GuiceCamelContext context = new GuiceCamelContext(injector);
context.setRegistry(rego);
context.addComponent("activemq", jmsCom);
最后是QueueHandlerImpl
代码:
public void handle(String body, Exchange exchange) throws JMSException {
try {
Thread.sleep(10000);
} catch (Exception ex ){
throw new RuntimeException(ex);
}
}
请注意正在进行工作的线程的持续时间明显长于jmsComponent
上设置的1秒。
运行示例时,我会收到消息," process"持续10秒,然后返回。但是,我已将事务超时设置为1,因此会期望"进程"由于事务超时设置而超时。但是,没有抛出异常,并且指定的bean引用仍然无法正常工作。
我错过了什么吗?
谢谢!