/
routing.xml
111 lines (96 loc) · 5.05 KB
/
routing.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2012 Red Hat, Inc.
Red Hat 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:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
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://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<!--
This sets up the Camel context - routes are defined in the Java Fluent API
in the TransactionalRouteBuilder class
-->
<camelContext id="transactions.camel" xmlns="http://camel.apache.org/schema/spring">
<package>org.fusesource.example.transactions.routes</package>
</camelContext>
<!--
Aries JTA provides a transaction manager that implements org.springframework.transaction.PlatformTransactionManager.
We can use <osgi:reference/> to lookup this service from the OSGi Service Registry and start using it in this Spring file
-->
<osgi:reference id="platformTxManager" interface="org.springframework.transaction.PlatformTransactionManager" />
<osgi:reference id="transactionManager" interface="javax.transaction.TransactionManager" />
<!-- needed by the ResourceManager in order to provide XA recovery -->
<osgi:reference id="recoverableTxManager" interface="org.apache.geronimo.transaction.manager.RecoverableTransactionManager" />
<!--
Setting up the amq:// components with a configuration that points to the JcaPooledConnectionFactory and the global
Spring PlatformTransactiongManager.
Note that transacted is set to 'false' because it's the JTA TransactionManager that manages the transactions and not
the JMS component itself.
-->
<bean id="amq" class="org.apache.camel.component.jms.JmsComponent">
<property name="configuration" ref="AMQConfig" />
</bean>
<bean id="AMQConfig" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="XAPooledCF" />
<property name="transacted" value="false" />
<property name="transactionManager" ref="platformTxManager" />
<property name="maxConcurrentConsumers" value="1" />
<property name="cacheLevelName" value="CACHE_NONE" />
</bean>
<!--
The JcaPooledConnectionFactory ensures that the JMS Sessions get enlisted in the global transaction manager
-->
<bean id="XAPooledCF" class="org.apache.activemq.pool.JcaPooledConnectionFactory" init-method="start" destroy-method="stop">
<property name="name" value="activemq.default" />
<property name="maxConnections" value="1" />
<property name="connectionFactory" ref="AmqXaCF" />
<property name="transactionManager" ref="transactionManager" />
</bean>
<!--
Defines an ActiveMQ XA-aware ConnectionFactory
-->
<bean id="AmqXaCF" class="org.apache.activemq.ActiveMQXAConnectionFactory">
<property name="brokerURL" value="failover:(tcp://localhost:61616)?jms.prefetchPolicy.all=1" />
<property name="userName" value="admin" />
<property name="password" value="admin" />
</bean>
<!-- A ResourceManager is needed for every transactional resource in order to
recover any outstanding transactions after a crash.
It will register with the Aries transaction manager, which then calls
recoverResource() on the transactional resource itself.
-->
<bean id="resourceManager-AMQ" class="org.apache.activemq.pool.ActiveMQResourceManager" init-method="recoverResource">
<property name="transactionManager" ref="recoverableTxManager" />
<!-- CF must be of type ActiveMQConnectionFactory, otherwise no recovery will occur -->
<property name="connectionFactory" ref="AmqXaCF" />
<property name="resourceName" value="activemq.default" />
</bean>
<!--
Setting up the jta:// component with the entity manager factory that we set
up in the 'database' bundle.
-->
<bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<osgi:reference id="entityManagerFactory" interface="javax.persistence.EntityManagerFactory" />
<!--
Defines the transactional policy we want to use.
-->
<bean id="PROPAGATION_REQUIRED" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
<property name="transactionManager" ref="platformTxManager" />
</bean>
</beans>