ActiveMQ是否支持多个交易消费者?
问题描述:
我正在ServiceMix中开发OSGI捆绑包以便从ActiveMQ的相同队列中使用。ActiveMQ是否支持多个交易消费者?
我需要确保邮件只有在每件事情都好的情况下才会出列,以便我不会丢失该邮件。所以我使用骆驼交易客户端。我按照这个教程来管理它http://camel.apache.org/transactional-client.html
但是,问题是,当部署许多使用相同队列的bundle时,我只能同时使用一个使用者。
我应该怎么做才能在ActiveMQ中启用并行事务消耗?
在此先感谢。
问候,
这是我实现(从教程只是复制):
骆驼路线:
<route>
<from uri="activemq:queue:foo"/>
<transacted ref="required"/>
<process ref="myProcessor"/>
<to uri="activemq:queue:bar"/>
</route>
Spring上下文:
<!-- setup 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>
<!-- setup spring jms TX manager -->
<bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
<property name="connectionFactory" ref="poolConnectionFactory"/>
</bean>
<!-- define our activemq component -->
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="connectionFactory" ref="poolConnectionFactory"/>
<!-- define the jms consumer/producer as transacted -->
<property name="transacted" value="true"/>
<!-- setup the transaction manager to use -->
<!-- if not provided then Camel will automatic use a JmsTransactionManager, however if you
for instance use a JTA transaction manager then you must configure it -->
<property name="transactionManager" ref="jmsTransactionManager"/>
</bean>
答
我终于在这里找到了解决方案http://activemq.2283324.n4.nabble.com/Blocking-transactions-td2354801.html;cid=1431937246689-831。
问题是由于预取限制。建议在存在多个消费者时将其置为0,即使它们不是事务性的。
所以我不得不通过增加destination.consumer.prefetchSize = 0这种方式来改变我的骆驼航线:
<route>
<from uri="activemq:queue:foo?destination.consumer.prefetchSize=0"/>
<transacted ref="required"/> <process ref="myProcessor"/>
<to uri="activemq:queue:bar"/>
</route>
答
是的使用ActiveMQ JMS可能让并发消费者。
<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="pooledConnectionFactory" />
<property name="transacted" value="true" />
<property name="concurrentConsumers" value="10" />
<property name="deliveryPersistent" value="true" />
<property name="requestTimeout" value="20000" />
<property name="cacheLevelName" value="CACHE_CONSUMER" />
</bean>
非常感谢@阿肖克 - 南大你的答案。使用Camel的activemq组件也可能有并发使用者。但是,这将为容器中的一个包创建一个线程池。结果就好像我在容器中部署了同一个包的许多实例。我需要的是将不同容器部署在不同容器中作为有竞争力的消费者。 – MedAbd