我正在尝试从部署到ServiceMix 5.4.0的Web服务向ActiveMQ队列发送一个消息。出于这个原因,我从camel上下文中获取了一个生成器模板,并按以下方式发送消息:
ProducerTemplate template = camelContext.createProducerTemplate();
template.send(
"activemq://ExecutePaymentInputQueue",
new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(
...
);
}
}
);
blueprint.xml中的相关部分:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.1.0"
xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://www.osgi.org/xmlns/blueprint-ext/v1.1.0 https://svn.apache.org/repos/asf/aries/tags/blueprint-0.3.1/blueprint-core/src/main/resources/org/apache/aries/blueprint/ext/blueprint-ext.xsd
http://cxf.apache.org/blueprint/jaxws http://cxf.apache.org/schemas/blueprint/jaxws.xsd
http://cxf.apache.org/blueprint/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd
http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
">
<!-- Transaction manager setup -->
<reference id="jtaTransactionManager" interface="javax.transaction.TransactionManager"/>
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<argument ref="jtaTransactionManager"/>
</bean>
<!-- Transaction policy setup -->
<bean id="DefaultTransactionPolicy" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
<property name="transactionManager" ref="transactionManager"/>
</bean>
<!-- BEGIN ActiveMQ -->
<bean id="activemqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616" />
<property name="userName" value="smx"/>
<property name="password" value="smx"/>
<property name="redeliveryPolicy">
<bean class="org.apache.activemq.RedeliveryPolicy">
<property name="maximumRedeliveries" value="360"/>
<property name="redeliveryDelay" value="10000"/>
</bean>
</property>
</bean>
<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="activemqConnectionFactory"/>
<property name="concurrentConsumers" value="8"/>
<property name="maxConcurrentConsumers" value="16"/>
<property name="transactionManager" ref="transactionManager"/>
</bean>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="jmsConfig" />
</bean>
<!-- JMS component setup -->
<!--<reference id="connectionFactory" interface="javax.jms.ConnectionFactory" />-->
<!-- END ActiveMQ -->
<!-- BEGIN SERVICE EXPORTS -->
<service interface="com.bssys.ebpp.core.api.PaymentService" >
<bean class="com.bssys.ebpp.core.services.impl.PaymentServiceImpl">
<tx:transaction method="*" value="Required"/>
</bean>
</service>
<!-- END SERVICE EXPORTS -->
<camelContext id="camelContext" xmlns="http://camel.apache.org/schema/blueprint"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://camel.apache.org/schema/blueprint/camel-blueprint-2.13.2.xsd">
...
</camelContext>
</blueprint>
当发送消息时,应该有一个打开的JTA事务(参见blueprint.xml中的声明性aries配置)。
问题是生产者似乎忽略了jta事务,并且消息被放到该事务之外的目标队列中(紧接在send方法返回之后)。如何更改此行为并使生产者加入JTA事务?