You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Steve Holmes <ia...@gmail.com> on 2010/04/21 22:12:41 UTC

Recieving the same message 10 times, Spring, and Camel

Hi All!
Keep in mind that I am completely new to ActiveMQ and message brokers in
general.  I've been setting up a configuration within spring using an
embedded broker and a Camel Context for consuming messages.  The problem I'm
having is that each time I produce a message and add it to it's ActiveMQ
destination Topic it appears that 10 messages go to the consumer.  I'm
basing this on printing out a message from a filter within camel each time
it receives a message.  Unfortunately, because I'm using the embedded broker
within spring, I don't appear to have access to any of the admin views (web
console or JConsole) that I would have with a dedicated broker.  Any help
would be greatly appreciated.  Here is my screen resources.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:amq="http://activemq.apache.org/schema/core"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
        http://activemq.apache.org/schema/core
        http://activemq.apache.org/schema/core/activemq-core-5.3.1.xsd
        http://camel.apache.org/schema/spring
        http://camel.apache.org/schema/spring/camel-spring.xsd
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">


    <amq:broker brokerName="test-broker"
dataDirectory="/Users/steve/Documents/activemq/data" start="true">
        <!-- The transport connectors ActiveMQ will listen to -->
        <amq:transportConnectors>
            <amq:transportConnector name="openwire"
uri="tcp://localhost:61616"/>
        </amq:transportConnectors>
    </amq:broker>

    <!-- use jencks connection pooling so its more effecient to send JMS
messages -->
    <!--brokerURL="tcp://localhost:61616"-->
    <!--<amqpool:pool id="jmsConnectionFactory"
xmlns:amqpool="http://jencks.org/amqpool/2.2"
                  brokerURL="vm://localhost"
                  maxConnections="8"/>-->


    <!--  ActiveMQ destinations to use  -->
    <bean id="frontPageLayoutTopic"
class="org.apache.activemq.command.ActiveMQTopic" autowire="constructor">
        <constructor-arg value="frontPageLayoutTopic"/>
    </bean>
    <bean id="badgeReceivedTopic"
class="org.apache.activemq.command.ActiveMQTopic" autowire="constructor">
        <constructor-arg value="badgeReceivedTopic"/>
    </bean>
    <bean id="queueDestination"
class="org.apache.activemq.command.ActiveMQQueue" autowire="constructor"/>

    <bean id="jmsConfig"
class="org.apache.camel.component.jms.JmsConfiguration">
        <property name="connectionFactory" ref="jmsFactory"/>
        <property name="transacted" value="false"/>
        <property name="concurrentConsumers" value="10"/>
    </bean>

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

    </bean>

    <!-- Spring JMS Template -->
    <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
        <property name="connectionFactory">
            <ref local="jmsFactory"/>
        </property>
        <property name="defaultDestination" ref="queueDestination"/>
    </bean>

    <!-- a sample POJO which uses a Spring JmsTemplate -->
    <bean id="frontPageLayoutPublisher"
class="com.tweety.route.FrontPageLayoutProducer">
        <property name="jmsTemplate" ref="jmsTemplate"/>
        <property name="destination" ref="frontPageLayoutTopic"/>
    </bean>

    <bean id="frontPageBadgeProcessor"
class="com.tweety.route.FrontPageBadgeFilter"/>
    <bean id="twitterAuthenticationFilter"
class="com.tweety.route.TwitterAuthenticationFilter"/>
    <bean id="twitterPoser" class="com.tweety.route.TwitterPoster"/>

    <!-- a pooling based JMS provider -->
    <bean id="jmsFactory"
class="org.apache.activemq.pool.PooledConnectionFactory"
destroy-method="stop">
        <property name="connectionFactory">
            <bean
class="org.apache.activemq.spring.ActiveMQConnectionFactory">
                <property name="brokerURL" value="vm://test-broker"/>
            </bean>
        </property>
    </bean>

    <bean id="frontPageLayoutToFrontPageBadgeProcess"
class="com.tweety.route.FrontPageLayoutToFrontPageBadgeProcess"/>
    <camelContext xmlns="http://camel.apache.org/schema/spring"
autoStartup="true">
        <routeBuilder ref="frontPageLayoutToFrontPageBadgeProcess"/>
    </camelContext>

</beans>

Thanks!
-Steve


-- 
View this message in context: http://old.nabble.com/Recieving-the-same-message-10-times%2C-Spring%2C-and-Camel-tp28300935p28300935.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Recieving the same message 10 times, Spring, and Camel

Posted by Norman Maurer <no...@apache.org>.
And of course the "ActiveMQ in Action" book is a really good source of
information..

Bye,
Norman


2010/4/22 Bruce Snyder <br...@gmail.com>:
> On Thu, Apr 22, 2010 at 10:59 AM, Steve Holmes <ia...@gmail.com> wrote:
>>
>> Hi!
>> Thanks for the response...so you're saying that the concurrentConsumers
>> setting tells activeMQ to push 10 messages.  If there is only one consumer
>> (camel route in this case) then it will push it to the one consumer 10
>> times.  So the key is you have to know ahead of time how many consumers you
>> are going to have?  Or if you set it to 1 will it push one at a time to all
>> your consumers?  Sorry, as I noted before I really am a newbie to this
>> technology.
>
> No, that's incorrect. The concurrentConsumers setting is the number of
> consumers you want to receive messages from a given destination at the
> same time (concurrently).
>
> If you are using topics, and a producer sends one message to the
> destination where 10 consumers are listening, each consumers will
> receive that single message.
>
> Since you are new to JMS, I highly suggest that you work through Sun's
> JMS tutorial:
>
> http://java.sun.com/products/jms/tutorial/1_3_1-fcs/doc/jms_tutorialTOC.html
>
> This will provide you with an understanding of JMS and now the
> messaging domains (i.e., queues and topics) each work.
>
> Then you should work through the ActiveMQ examples to become familiar
> with ActiveMQ:
>
> http://activemq.apache.org/examples.html
>
> I think doing so will explain a lot for you.
>
> Bruce
> --
> perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
> );'
>
> ActiveMQ in Action: http://bit.ly/2je6cQ
> Blog: http://bruceblog.org/
> Twitter: http://twitter.com/brucesnyder
>

Re: Recieving the same message 10 times, Spring, and Camel

Posted by Bruce Snyder <br...@gmail.com>.
On Thu, Apr 22, 2010 at 10:59 AM, Steve Holmes <ia...@gmail.com> wrote:
>
> Hi!
> Thanks for the response...so you're saying that the concurrentConsumers
> setting tells activeMQ to push 10 messages.  If there is only one consumer
> (camel route in this case) then it will push it to the one consumer 10
> times.  So the key is you have to know ahead of time how many consumers you
> are going to have?  Or if you set it to 1 will it push one at a time to all
> your consumers?  Sorry, as I noted before I really am a newbie to this
> technology.

No, that's incorrect. The concurrentConsumers setting is the number of
consumers you want to receive messages from a given destination at the
same time (concurrently).

If you are using topics, and a producer sends one message to the
destination where 10 consumers are listening, each consumers will
receive that single message.

Since you are new to JMS, I highly suggest that you work through Sun's
JMS tutorial:

http://java.sun.com/products/jms/tutorial/1_3_1-fcs/doc/jms_tutorialTOC.html

This will provide you with an understanding of JMS and now the
messaging domains (i.e., queues and topics) each work.

Then you should work through the ActiveMQ examples to become familiar
with ActiveMQ:

http://activemq.apache.org/examples.html

I think doing so will explain a lot for you.

Bruce
-- 
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'

ActiveMQ in Action: http://bit.ly/2je6cQ
Blog: http://bruceblog.org/
Twitter: http://twitter.com/brucesnyder

Re: Recieving the same message 10 times, Spring, and Camel

Posted by Steve Holmes <ia...@gmail.com>.
Hi!
Thanks for the response...so you're saying that the concurrentConsumers
setting tells activeMQ to push 10 messages.  If there is only one consumer
(camel route in this case) then it will push it to the one consumer 10
times.  So the key is you have to know ahead of time how many consumers you
are going to have?  Or if you set it to 1 will it push one at a time to all
your consumers?  Sorry, as I noted before I really am a newbie to this
technology.
Thanks!
-Steve

bsnyder wrote:
> 
> On Wed, Apr 21, 2010 at 7:31 PM, Steve Holmes <ia...@gmail.com>
> wrote:
>>
>> It appears that it is the concurrent consumers setting.  Does anyone know
>> how
>> this should be set properly?  When I commented it out:
>>
>> <!--<property name="concurrentConsumers" value="10"/>-->
>>
>> I'm now only receiving the message once.  Shouldn't the messages only be
>> pushed once to each consumer regardless of this setting?
> 
> Yes, and that is exactly what is happening. You specified 10 consumers
> working concurrently on the same topic. With JMS topics, each
> subscriber receives a copy of the every message on the topic. So, 1
> message * 10 consumers = 10 messages in total.
> 
> Bruce
> -- 
> perl -e 'print
> unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
> );'
> 
> ActiveMQ in Action: http://bit.ly/2je6cQ
> Blog: http://bruceblog.org/
> Twitter: http://twitter.com/brucesnyder
> 
> 

-- 
View this message in context: http://old.nabble.com/Recieving-the-same-message-10-times%2C-Spring%2C-and-Camel-tp28300935p28331760.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Recieving the same message 10 times, Spring, and Camel

Posted by Bruce Snyder <br...@gmail.com>.
On Wed, Apr 21, 2010 at 7:31 PM, Steve Holmes <ia...@gmail.com> wrote:
>
> It appears that it is the concurrent consumers setting.  Does anyone know how
> this should be set properly?  When I commented it out:
>
> <!--<property name="concurrentConsumers" value="10"/>-->
>
> I'm now only receiving the message once.  Shouldn't the messages only be
> pushed once to each consumer regardless of this setting?

Yes, and that is exactly what is happening. You specified 10 consumers
working concurrently on the same topic. With JMS topics, each
subscriber receives a copy of the every message on the topic. So, 1
message * 10 consumers = 10 messages in total.

Bruce
-- 
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'

ActiveMQ in Action: http://bit.ly/2je6cQ
Blog: http://bruceblog.org/
Twitter: http://twitter.com/brucesnyder

Re: Recieving the same message 10 times, Spring, and Camel

Posted by Steve Holmes <ia...@gmail.com>.
It appears that it is the concurrent consumers setting.  Does anyone know how
this should be set properly?  When I commented it out:

<!--<property name="concurrentConsumers" value="10"/>-->

I'm now only receiving the message once.  Shouldn't the messages only be
pushed once to each consumer regardless of this setting?
-Steve



Steve Holmes wrote:
> 
> Hi All!
> Keep in mind that I am completely new to ActiveMQ and message brokers in
> general.  I've been setting up a configuration within spring using an
> embedded broker and a Camel Context for consuming messages.  The problem
> I'm having is that each time I produce a message and add it to it's
> ActiveMQ destination Topic it appears that 10 messages go to the consumer. 
> I'm basing this on printing out a message from a filter within camel each
> time it receives a message.  Unfortunately, because I'm using the embedded
> broker within spring, I don't appear to have access to any of the admin
> views (web console or JConsole) that I would have with a dedicated broker. 
> Any help would be greatly appreciated.  Here is my screen resources.xml
> file:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
>        xmlns:amq="http://activemq.apache.org/schema/core"
>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>        xsi:schemaLocation="
>         http://activemq.apache.org/schema/core
>         http://activemq.apache.org/schema/core/activemq-core-5.3.1.xsd
>         http://camel.apache.org/schema/spring
>         http://camel.apache.org/schema/spring/camel-spring.xsd
>         http://www.springframework.org/schema/beans
>         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
> 
> 
>     <amq:broker brokerName="test-broker"
> dataDirectory="/Users/steve/Documents/activemq/data" start="true">
>         <!-- The transport connectors ActiveMQ will listen to -->
>         <amq:transportConnectors>
>             <amq:transportConnector name="openwire"
> uri="tcp://localhost:61616"/>
>         </amq:transportConnectors>
>     </amq:broker>
> 
>     <!-- use jencks connection pooling so its more effecient to send JMS
> messages -->
>     <!--brokerURL="tcp://localhost:61616"-->
>     <!--<amqpool:pool id="jmsConnectionFactory"
> xmlns:amqpool="http://jencks.org/amqpool/2.2"
>                   brokerURL="vm://localhost"
>                   maxConnections="8"/>-->
> 
> 
>     <!--  ActiveMQ destinations to use  -->
>     <bean id="frontPageLayoutTopic"
> class="org.apache.activemq.command.ActiveMQTopic" autowire="constructor">
>         <constructor-arg value="frontPageLayoutTopic"/>
>     </bean>
>     <bean id="badgeReceivedTopic"
> class="org.apache.activemq.command.ActiveMQTopic" autowire="constructor">
>         <constructor-arg value="badgeReceivedTopic"/>
>     </bean>
>     <bean id="queueDestination"
> class="org.apache.activemq.command.ActiveMQQueue" autowire="constructor"/>
> 
>     <bean id="jmsConfig"
> class="org.apache.camel.component.jms.JmsConfiguration">
>         <property name="connectionFactory" ref="jmsFactory"/>
>         <property name="transacted" value="false"/>
>         <property name="concurrentConsumers" value="10"/>
>     </bean>
> 
>     <bean id="activemq"
> class="org.apache.activemq.camel.component.ActiveMQComponent">
>         <property name="configuration" ref="jmsConfig"/>
> 
>     </bean>
> 
>     <!-- Spring JMS Template -->
>     <bean id="jmsTemplate"
> class="org.springframework.jms.core.JmsTemplate">
>         <property name="connectionFactory">
>             <ref local="jmsFactory"/>
>         </property>
>         <property name="defaultDestination" ref="queueDestination"/>
>     </bean>
> 
>     <!-- a sample POJO which uses a Spring JmsTemplate -->
>     <bean id="frontPageLayoutPublisher"
> class="com.tweety.route.FrontPageLayoutProducer">
>         <property name="jmsTemplate" ref="jmsTemplate"/>
>         <property name="destination" ref="frontPageLayoutTopic"/>
>     </bean>
> 
>     <bean id="frontPageBadgeProcessor"
> class="com.tweety.route.FrontPageBadgeFilter"/>
>     <bean id="twitterAuthenticationFilter"
> class="com.tweety.route.TwitterAuthenticationFilter"/>
>     <bean id="twitterPoser" class="com.tweety.route.TwitterPoster"/>
> 
>     <!-- a pooling based JMS provider -->
>     <bean id="jmsFactory"
> class="org.apache.activemq.pool.PooledConnectionFactory"
> destroy-method="stop">
>         <property name="connectionFactory">
>             <bean
> class="org.apache.activemq.spring.ActiveMQConnectionFactory">
>                 <property name="brokerURL" value="vm://test-broker"/>
>             </bean>
>         </property>
>     </bean>
> 
>     <bean id="frontPageLayoutToFrontPageBadgeProcess"
> class="com.tweety.route.FrontPageLayoutToFrontPageBadgeProcess"/>
>     <camelContext xmlns="http://camel.apache.org/schema/spring"
> autoStartup="true">
>         <routeBuilder ref="frontPageLayoutToFrontPageBadgeProcess"/>
>     </camelContext>
> 
> </beans>
> 
> Thanks!
> -Steve
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Recieving-the-same-message-10-times%2C-Spring%2C-and-Camel-tp28300935p28323303.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.