2012-03-27 4 views
2

メッセージキューとコンシューマコンシューマを同時に使用していたActiveMQ/Camel構成があります。ActiveMQ:キュー(コンシューマコンシューマを含む)とトピックの両方を使用した正しい設​​定

しかし、ここではメッセージトピックを紹介しています。同時コンシューマのために、トピックで受信したメッセージは数回消費されます。

このシナリオの正しい設定は何ですか?

つまり、キューで受信したメッセージに対して複数のコンシューマコンシューマを必要としますが、トピックで受信したメッセージに対して定義されたコンシューマは1つだけです。ここで

が現在の設定です:

<amq:connectionFactory id="amqConnectionFactory" 
    useAsyncSend="true" brokerURL="${${ptl.Servername}.jms.cluster.uri}" 
    userName="${jms.username}" password="${jms.password}" sendTimeout="1000" 
    optimizeAcknowledge="true" disableTimeStampsByDefault="true"> 
</amq:connectionFactory> 

<bean id="cachingConnectionFactory" 
    class="org.springframework.jms.connection.CachingConnectionFactory"> 
    <property name="targetConnectionFactory" ref="amqConnectionFactory"></property> 
    <property name="cacheConsumers" value="true"></property> 
    <property name="cacheProducers" value="true"></property> 
    <property name="reconnectOnException" value="true"></property> 
    <property name="sessionCacheSize" value="${jms.sessioncachesize}"></property> 
</bean> 

<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration"> 
    <property name="connectionFactory" ref="cachingConnectionFactory" /> 
    <property name="transacted" value="false" /> 
    <property name="concurrentConsumers" value="${jms.concurrentConsumer}" /> 
    <property name="maxConcurrentConsumers" value="${jms.max.concurrentConsumer}" /> 
    <property name="preserveMessageQos" value="true" /> 
    <property name="timeToLive" value="${jms.timeToLive}" /> 
</bean> 

<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent"> 
    <property name="configuration" ref="jmsConfig" /> 
</bean> 

答えて

3

あなたが明示的に設定することができますconcurrentConsumers/maxConcurrentConsumersを次のように

総構成ガイドに見えますトピック消費者の場合は「1」に設定します。

from("activemq:topic:myTopic?concurrentConsumers=1&maxConcurrentConsumers=1")... 

は、代わりに、「1」にJmsConfiguration同時/ maxConcurrentConsumersプロパティを設定し、必要に応じて明示的にキューの同時消費を可能にします。

from("activemq:queue:myQueue?maxConcurrentConsumers=5")... 

また、あなたが重複を得ることなくトピックメッセージの同時消費を実行するためにVirtual Topicsを使用することができます

(非常に伝統的なトピックの上にお勧めします)
0

私が使用して終了ソリューションは、別々のjmsConfig/ActiveMQのコンフィグブロックを作成することでした。

<!-- This is appropriate for consuming Queues, but not topics. For topics, use 
jmsTopicConfig/activemqTopics --> 
<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration"> 
    <property name="connectionFactory" ref="cachingConnectionFactory" /> 
    <property name="transacted" value="false" /> 
    <property name="concurrentConsumers" value="${jms.concurrentConsumer}" /> 
    <property name="maxConcurrentConsumers" value="${jms.max.concurrentConsumer}" /> 
    <property name="preserveMessageQos" value="true" /> 
    <property name="timeToLive" value="${jms.timeToLive}" /> 
</bean> 

<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent"> 
    <property name="configuration" ref="jmsConfig" /> 
</bean> 

<!-- This config limits to a single concurrent consumer. This config is appropriate for 
consuming Topics, not Queues. --> 
<bean id="jmsTopicConfig" class="org.apache.camel.component.jms.JmsConfiguration"> 
    <property name="connectionFactory" ref="cachingConnectionFactory" /> 
    <property name="transacted" value="false" /> 
    <property name="concurrentConsumers" value="1" /> 
    <property name="maxConcurrentConsumers" value="1" /> 
    <property name="preserveMessageQos" value="true" /> 
    <property name="timeToLive" value="${jms.timeToLive}" /> 
</bean> 

<bean id="activemqTopics" class="org.apache.activemq.camel.component.ActiveMQComponent"> 
    <property name="configuration" ref="jmsTopicConfig" /> 
</bean> 

を次に、ラクダのパイプラインで、activemqTopics豆オフトピックを消費し、次のように、::

<camel:route id="myTopicResponder"> 
    <camel:from uri="activemqTopics:topic:stockQuotes?concurrentConsumers=1" /> 
    <camel:to uri="bean:stockQuoteResponder?method=saveStockQuote"/> 
</camel:route> 
関連する問題