| <?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:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| xmlns:camel="http://camel.apache.org/schema/spring" |
| 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"> |
| |
| <!-- START SNIPPET: e1 --> |
| <!-- here we define our camel context --> |
| <camelContext id="myroutes" xmlns="http://camel.apache.org/schema/spring"> |
| <!-- disable JMX during testing --> |
| <jmxAgent id="agent" disabled="true"/> |
| <!-- and now our route using the XML syntax --> |
| <route errorHandlerRef="errorHandler"> |
| <!-- 1: from the jms queue --> |
| <from uri="activemq:queue:okay"/> |
| <!-- 2: setup the transactional boundaries to require a transaction --> |
| <transacted ref="PROPAGATION_REQUIRED"/> |
| <!-- 3: call our business logic that is myProcessor --> |
| <process ref="myProcessor"/> |
| <!-- 4: choice --> |
| <choice> |
| <when> |
| <simple>${in.header.count} < 3</simple> |
| <rollback message="Please rollback"/> |
| </when> |
| </choice> |
| <!-- 5: if success then send it to the mock --> |
| <to uri="mock:result"/> |
| </route> |
| </camelContext> |
| |
| <!-- this bean is our business logic --> |
| <bean id="myProcessor" class="org.apache.camel.component.jms.tx.JMSTransactionalClientWithRollbackTest$MyProcessor"/> |
| <!-- END SNIPPET: e1 --> |
| |
| <!-- START SNIPPET: e2 --> |
| <!-- the transactional error handler --> |
| <bean id="errorHandler" class="org.apache.camel.spring.spi.TransactionErrorHandlerBuilder"> |
| <property name="springTransactionPolicy" ref="PROPAGATION_REQUIRED"/> |
| </bean> |
| |
| <!-- jms connection factory --> |
| <bean id="poolConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory"> |
| <property name="maxConnections" value="8"/> |
| <property name="connectionFactory" ref="jmsConnectionFactory"/> |
| </bean> |
| |
| <bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"> |
| <property name="brokerURL" value="vm://localhost?broker.persistent=false&broker.useJmx=false"/> |
| </bean> |
| |
| <!-- jms transaction manager --> |
| <bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager"> |
| <property name="connectionFactory" ref="poolConnectionFactory"/> |
| </bean> |
| |
| <!-- jms component configuration --> |
| <bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration"> |
| <property name="connectionFactory" ref="poolConnectionFactory"/> |
| <property name="transactionManager" ref="jmsTransactionManager"/> |
| <property name="transacted" value="true"/> |
| <property name="concurrentConsumers" value="1"/> |
| </bean> |
| |
| <!-- activemq component --> |
| <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent"> |
| <property name="configuration" ref="jmsConfig"/> |
| </bean> |
| |
| <!-- spring required policy --> |
| <bean id="PROPAGATION_REQUIRED" class="org.apache.camel.spring.spi.SpringTransactionPolicy"> |
| <constructor-arg> |
| <bean class="org.springframework.transaction.support.TransactionTemplate"> |
| <property name="transactionManager" ref="jmsTransactionManager"/> |
| </bean> |
| </constructor-arg> |
| </bean> |
| <!-- END SNIPPET: e2 --> |
| |
| </beans> |