You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Nhan Nguyen <nt...@gmail.com> on 2013/08/04 10:04:48 UTC

The producer sent only one message but the comsumer received multiple messages with same content.

Hi all,

I am using a Topic to send and receive the message:

from("jms:topic:topic1").process(new Processor() {
					
	@Override
	public void process(Exchange exchange) throws Exception {
		System.out.println(exchange.getIn().getBody());
	}
});


The code to send the message:

endPoint = getCamelContext().getEndpoint("jms:topic:topic1",
JmsEndpoint.class);
producer = getCamelContext().createProducerTemplate();
int i = 0;
while(true){
	Exchange exchange = endpoint.createExchange();
        exchange.setPattern(ExchangePattern.InOnly);
	exchange .setBody(i++);
	m_producer.send(endPoint, exchange);
	Thread.sleep(1000);
}

I sent a message, wait for 1second, then send another with the content is
i++. And the output I saw:

0
1
1
2
2
2
3
3
3
3

Why did I receive so many same messages? I expected the result must be:
0
1
2
3


Can someone help me on this? Thanks!



--
View this message in context: http://camel.465427.n5.nabble.com/The-producer-sent-only-one-message-but-the-comsumer-received-multiple-messages-with-same-content-tp5736733.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: The producer sent only one message but the comsumer received multiple messages with same content.

Posted by Nhan Nguyen <nt...@gmail.com>.
Note: If I use the PollingConsumer, I don't see this problem.



--
View this message in context: http://camel.465427.n5.nabble.com/The-producer-sent-only-one-message-but-the-comsumer-received-multiple-messages-with-same-content-tp5736733p5736734.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: The producer sent only one message but the comsumer received multiple messages with same content.

Posted by Christian Müller <ch...@gmail.com>.
Good to know you could solve the problem.

Best,
Christian
Am 06.08.2013 16:56 schrieb "Nhan Nguyen" <nt...@gmail.com>:

> Thanks for your reply!
>
> I find out the reason: I used a topic and set the
> maximumConcurrrentConsumer
> = 10. This is really not recommended. I read some documents about the
> concurrent consumer and see that we should only set the concurrentconsumer
> if we are using a queue.
>
> I also find out another discuss thread about this:
>
> http://camel.465427.n5.nabble.com/concurrentConsumers-basic-question-td4535789.html
>
> Thanks all for your support!
> Nhan
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/The-producer-sent-only-one-message-but-the-comsumer-received-multiple-messages-with-same-content-tp5736733p5736856.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: The producer sent only one message but the comsumer received multiple messages with same content.

Posted by Nhan Nguyen <nt...@gmail.com>.
Thanks for your reply!

I find out the reason: I used a topic and set the maximumConcurrrentConsumer
= 10. This is really not recommended. I read some documents about the
concurrent consumer and see that we should only set the concurrentconsumer
if we are using a queue.

I also find out another discuss thread about this:
http://camel.465427.n5.nabble.com/concurrentConsumers-basic-question-td4535789.html

Thanks all for your support!
Nhan



--
View this message in context: http://camel.465427.n5.nabble.com/The-producer-sent-only-one-message-but-the-comsumer-received-multiple-messages-with-same-content-tp5736733p5736856.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: The producer sent only one message but the comsumer received multiple messages with same content.

Posted by "John D. Ament" <jo...@gmail.com>.
Since you have activemq, can you try it with the activemq component
rather than the JMS component?


Can you share more of your example, the problem is that it doesn't compile.

I put together a simple example as well that demos this, but doesn't
reproduce your error.  I'm wondering if somehow you're setting up more
processors within your loop.

final String RS_BASIC_ENDPOINT =
"cxfrs://http://0.0.0.0:9581/rest/?resourceClasses=com.mycompany.rest.LoadUpResource";
final JmsEndpoint endPoint=
ctx.getEndpoint("activemq:topic:topic1",JmsEndpoint.class);
final ProducerTemplate producer = ctx.createProducerTemplate();
from(RS_BASIC_ENDPOINT).process(new Processor(){
@Override
public void process(final Exchange exchange) throws Exception {
for(int i=0;i<10;i++) {
Exchange outExchange = endPoint.createExchange();
outExchange.setPattern(ExchangePattern.InOnly);
outExchange.getIn().setBody(i);
producer.send(endPoint, outExchange);
}
}
});


from("activemq:topic:topic1").process(new Processor(){
@Override
public void process(final Exchange exchange) throws Exception {
logger.info("footopicProcessor "+exchange.getIn().getBody());
}
});

On Tue, Aug 6, 2013 at 9:35 AM, Nhan Nguyen <nt...@gmail.com> wrote:
> I'm using Camel 2.11.0:
>
> <dependency>
>             <groupId>org.apache.camel</groupId>
>             <artifactId>camel-core</artifactId>
>                         <version>2.11.0</version>
>         </dependency>
>         <dependency>
>             <groupId>org.apache.camel</groupId>
>             <artifactId>camel-jms</artifactId>
>                         <version>2.11.0</version>
>         </dependency>
>         <dependency>
>             <groupId>org.apache.camel</groupId>
>             <artifactId>camel-spring</artifactId>
>                         <version>2.11.0</version>
>         </dependency>
>         <dependency>
>             <groupId>org.apache.activemq</groupId>
>             <artifactId>activemq-camel</artifactId>
>                         <version>5.7.0</version>
>         </dependency>
>
> Thanks,
> Nhan
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/The-producer-sent-only-one-message-but-the-comsumer-received-multiple-messages-with-same-content-tp5736733p5736850.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

Re: The producer sent only one message but the comsumer received multiple messages with same content.

Posted by Nhan Nguyen <nt...@gmail.com>.
I'm using Camel 2.11.0:

<dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
			<version>2.11.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jms</artifactId>
			<version>2.11.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring</artifactId>
			<version>2.11.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-camel</artifactId>
			<version>5.7.0</version>
        </dependency>

Thanks,
Nhan



--
View this message in context: http://camel.465427.n5.nabble.com/The-producer-sent-only-one-message-but-the-comsumer-received-multiple-messages-with-same-content-tp5736733p5736850.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: The producer sent only one message but the comsumer received multiple messages with same content.

Posted by Christian Müller <ch...@gmail.com>.
Which version of Camel do you use?

Best,
Christian
Am 06.08.2013 12:30 schrieb "Nhan Nguyen" <nt...@gmail.com>:

> Can someone help me on this?
>
> Seem there is a problem with the processor when it is used with the Topic.
>
> Thanks,
> Nhan
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/The-producer-sent-only-one-message-but-the-comsumer-received-multiple-messages-with-same-content-tp5736733p5736829.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: The producer sent only one message but the comsumer received multiple messages with same content.

Posted by Nhan Nguyen <nt...@gmail.com>.
Can someone help me on this?

Seem there is a problem with the processor when it is used with the Topic.

Thanks,
Nhan



--
View this message in context: http://camel.465427.n5.nabble.com/The-producer-sent-only-one-message-but-the-comsumer-received-multiple-messages-with-same-content-tp5736733p5736829.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: The producer sent only one message but the comsumer received multiple messages with same content.

Posted by Nhan Nguyen <nt...@gmail.com>.
Thanks Christian for your test.

I had a look on your UT and re-checked my code. There is no problem with the
topic and the route config. The problem seem comes from Processor.

from("jms:topic:topic1").process(new Processor() { 

        @Override 
        public void process(Exchange exchange) throws Exception { 
                System.out.println(exchange.getIn().getBody()); 
        } 
}); 

There is only one message sent to the endpoint but seem the processor was
executed multiple times. Is there any problem with the ThreadExecutor inside
the consumer?

Thanks,
Nhan



--
View this message in context: http://camel.465427.n5.nabble.com/The-producer-sent-only-one-message-but-the-comsumer-received-multiple-messages-with-same-content-tp5736733p5736752.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: The producer sent only one message but the comsumer received multiple messages with same content.

Posted by Christian Müller <ch...@gmail.com>.
Ok, than it's the right decision...
I think there must be something wrong in your route set up. The number of
messages you receives is increasing by one for each loop...
I added the unit test testMultipleMessagesOnSameTopic() [1] to make sure it
works. Please have a look and check what you are doing different.

[1]
https://git-wip-us.apache.org/repos/asf?p=camel.git;a=blob;f=components/camel-jms/src/test/java/org/apache/camel/component/jms/TwoConsumerOnSameTopicTest.java;h=a389fa25363ea8578d63ed9c86803bcfd080ea68;hb=HEAD

Best,
Christian
-----------------

Software Integration Specialist

Apache Camel committer: https://camel.apache.org/team
V.P. Apache Camel: https://www.apache.org/foundation/
Apache Member: https://www.apache.org/foundation/members.html

https://www.linkedin.com/pub/christian-mueller/11/551/642


On Sun, Aug 4, 2013 at 12:34 PM, Nhan Nguyen <nt...@gmail.com> wrote:

> Hi Christian,
>
> I have plan I will use multiple comsumers.
>
> Thanks,
> Nhan
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/The-producer-sent-only-one-message-but-the-comsumer-received-multiple-messages-with-same-content-tp5736733p5736739.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: The producer sent only one message but the comsumer received multiple messages with same content.

Posted by Nhan Nguyen <nt...@gmail.com>.
Hi Christian,

I have plan I will use multiple comsumers.

Thanks,
Nhan



--
View this message in context: http://camel.465427.n5.nabble.com/The-producer-sent-only-one-message-but-the-comsumer-received-multiple-messages-with-same-content-tp5736733p5736739.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: The producer sent only one message but the comsumer received multiple messages with same content.

Posted by Christian Müller <ch...@gmail.com>.
Why do you use a topic and not a queue if you only have one consumer?

Best,
Christian
-----------------

Software Integration Specialist

Apache Camel committer: https://camel.apache.org/team
V.P. Apache Camel: https://www.apache.org/foundation/
Apache Member: https://www.apache.org/foundation/members.html

https://www.linkedin.com/pub/christian-mueller/11/551/642


On Sun, Aug 4, 2013 at 10:04 AM, Nhan Nguyen <nt...@gmail.com> wrote:

> Hi all,
>
> I am using a Topic to send and receive the message:
>
> from("jms:topic:topic1").process(new Processor() {
>
>         @Override
>         public void process(Exchange exchange) throws Exception {
>                 System.out.println(exchange.getIn().getBody());
>         }
> });
>
>
> The code to send the message:
>
> endPoint = getCamelContext().getEndpoint("jms:topic:topic1",
> JmsEndpoint.class);
> producer = getCamelContext().createProducerTemplate();
> int i = 0;
> while(true){
>         Exchange exchange = endpoint.createExchange();
>         exchange.setPattern(ExchangePattern.InOnly);
>         exchange .setBody(i++);
>         m_producer.send(endPoint, exchange);
>         Thread.sleep(1000);
> }
>
> I sent a message, wait for 1second, then send another with the content is
> i++. And the output I saw:
>
> 0
> 1
> 1
> 2
> 2
> 2
> 3
> 3
> 3
> 3
>
> Why did I receive so many same messages? I expected the result must be:
> 0
> 1
> 2
> 3
>
>
> Can someone help me on this? Thanks!
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/The-producer-sent-only-one-message-but-the-comsumer-received-multiple-messages-with-same-content-tp5736733.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>