如何配置camel路由以使用与数据库的事务

时间:2017-03-03 04:56:07

标签: apache-camel blueprint apache-servicemix

我需要在Karaf下使用OSGI应用程序处理事务(我正在使用ServiceMix 7.0)。所有逻辑都在骆驼路线下。 首先,我接收Web请求并在路由中处理它,进行转换然后我需要启动事务:在Oracle中调用storedProcedures,调用另一个Web服务,如果调用Web服务成功,我需要提交存储过程调用,否则回滚。可能正在使用EJB或JTA中的容器管理事务。 Camel没有用于调用存储过程的开箱即用组件。所以我使用的是org.springframework.jdbc.object.StoredProcedure。现在我不知道如何使用事务上下文进行SP调用。

1 个答案:

答案 0 :(得分:1)

以下是您可以做的事情:

from("direct:mainRoute")
   .transacted()
   .to("direct:invokeService")
   .to("sql-stored:SUBNUMBERS(INTEGER ${headers.num1},INTEGER ${headers.num2},OUT INTEGER resultofsub)

您还需要将TransactionManager添加到上下文中。

<!-- spring transaction manager -->
<!-- this is the transaction manager Camel will use for transacted routes -->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource"/>
</bean>

有关Camel SQL存储过程组件的更多详细信息,请参阅: http://camel.apache.org/sql-stored-procedure.html