blob: 56ee0e356e5f81a7036be0a8e4857468b64bc021 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:broker="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.5.0.xsd">
<!-- jdbc idempotent repository -->
<bean id="messageIdRepository" class="org.apache.camel.processor.idempotent.jdbc.JdbcMessageIdRepository">
<constructor-arg index="0" ref="myDataSource"/>
<constructor-arg index="1" ref="requiredTemplate"/>
<constructor-arg index="2" value="myProcessor"/>
</bean>
<!-- use required TX -->
<bean id="requiredTemplate" class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager" ref="jtaTransactionManager"/>
</bean>
<bean id="required" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
<property name="transactionTemplate" ref="requiredTemplate"/>
</bean>
<!-- setup Atomikos for XA transaction -->
<bean id="atomikosTransactionManager"
class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init" destroy-method="close" depends-on="my-broker">
<!-- when close is called, should we force transactions to terminate or not? -->
<property name="forceShutdown" value="false"/>
</bean>
<!-- this is some atomikos setup you must do -->
<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp" depends-on="my-broker">
<property name="transactionTimeout" value="300"/>
</bean>
<!-- this is some atomikos setup you must do -->
<bean id="connectionFactory"
class="com.atomikos.jms.AtomikosConnectionFactoryBean"
init-method="init" destroy-method="close" depends-on="my-broker">
<property name="uniqueResourceName" value="myUniqueResource"/>
<property name="xaConnectionFactory" ref="jmsXaConnectionFactory"/>
</bean>
<!-- this is the Spring JtaTransactionManager which under the hood uses Atomikos -->
<bean id="jtaTransactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager" depends-on="my-broker">
<property name="transactionManager" ref="atomikosTransactionManager"/>
<property name="userTransaction" ref="atomikosUserTransaction"/>
</bean>
<!-- Is the ConnectionFactory to connect to the JMS broker -->
<!-- notice how we must use the XA connection factory -->
<bean id="jmsXaConnectionFactory" class="org.apache.activemq.ActiveMQXAConnectionFactory" depends-on="my-broker">
<property name="brokerURL" value="tcp://localhost:61616"/>
</bean>
<!-- define the activemq Camel component so we can integrate with the AMQ broker below -->
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent" depends-on="my-broker">
<!-- must indicate that we use transacted acknowledge mode -->
<property name="transacted" value="true"/>
<!-- refer to the transaction manager -->
<property name="transactionManager" ref="jtaTransactionManager"/>
</bean>
<!-- setup a local JMS Broker for testing purpose -->
<broker:broker id="my-broker" useJmx="false" persistent="false" brokerName="localhost">
<broker:transportConnectors>
<broker:transportConnector uri="tcp://localhost:61616"/>
</broker:transportConnectors>
</broker:broker>
<!-- define the datasource to the database - in this example we use an in memory database using HSQLDB -->
<!-- HSQLDB is not XA compatible so we wrap that using a special Atomikos NonXA to XA DataSource -->
<bean id="myDataSource" class="com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean" destroy-method="close">
<property name="uniqueResourceName" value="hsqldb"/>
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
<property name="url" value="jdbc:hsqldb:mem:mydatabase"/>
<property name="user" value="sa"/>
<property name="password" value=""/>
<property name="poolSize" value="3"/>
</bean>
<!-- datasource used to create the database tables -->
<bean id="myNonXADataSource" class="org.springframework.jdbc.datasource.SingleConnectionDataSource" destroy-method="destroy">
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
<property name="url" value="jdbc:hsqldb:mem:mydatabase"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>
</beans>