transactions - ActiveMQ 是否支持多个事务性消费者?

标签 transactions apache-camel activemq apache-servicemix

我正在 ServiceMix 中开发 OSGI 包以从同一个 ActiveMQ 队列中使用。

我需要确保只有在一切正常时消息才会出队,这样我就不会丢失该消息。所以我使用了 Camel 交易客户端。我按照本教程设法实现了它 http://camel.apache.org/transactional-client.html

但是,问题是当部署许多从同一个队列消费的 bundle 时,我只会让一个消费者同时工作。

我应该怎么做才能在 ActiveMQ 中启用并行事务消费?

提前致谢。

问候,


这是我的实现(刚刚从教程中复制):

Camel 路线:

   <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&amp;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 来改变我的 Camel 路线:

<route> 
<from uri="activemq:queue:foo?destination.consumer.prefetchSize=0"/>
<transacted ref="required"/> <process ref="myProcessor"/>
<to uri="activemq:queue:bar"/>
</route>

关于transactions - ActiveMQ 是否支持多个事务性消费者?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30234777/

相关文章:

c# - TransactionScope 的层次结构

java - Apache Camel - 基于正文聚合消息

jdbc - Camel : use datasource configured by spring-boot

c# - 将数据读取器与 sqltransactions 一起使用

sql - 如何仅为当前进程禁用 SQL Server 触发器?

java - 从 Camel 路由发送响应

security - ActiveMQ 和客户端通过证书身份验证身份

activemq - JMS 消息优先级不适用于消息

mysql - 如何锁定事务以读取一行然后插入 Hibernate?

java - Apache Camel : Stop exchange from proceeding to delete=true