Multiple consumers getting created in custom endpoint

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Multiple consumers getting created in custom endpoint

Manish K Bafna
Hi,
I am creating my own custom endpoint using Camel 1.5

public class AbcEndpoint extends DefaultEndpoint {
public Consumer createConsumer(Processor processor) throws Exception {
            Consumer c=new AbcConsumer(this,processor);
            return c;
      }
.....
}

public class AbcConsumer extends DefaultConsumer<DefaultExchange>
{
protected void doStart() throws Exception {..do something...}
protected void doStop() throws Exception {--do something--}
}

When is start the context for the 1st time, 1 consumer is created, when I stop it and start it again, createConsumer() is called 2 times and so on.
Do I have to do something to avoid this behavior. The problem is in the doStart() method of the Consumer, I am creating my own threads. Now since createConsumer() is being 2 times, doStart() is being called 2 times and multiple threads are being created.





Reply | Threaded
Open this post in threaded view
|

RE: Multiple consumers getting created in custom endpoint

Manish K Bafna
The same is visible in JMS component too.
Steps:
1. Create a route from JMS topic1 to JMS queue1
2. Start the context
3. Send 1 message to the topic.
4. The queue will also receive 1 message.
5. Stop the context
6. Start the context again
7. Send 1 message to the topic.
8. the same message will be seen in the queue 2 times when there should be only 1.
9. Repeat the above steps and the number increases.

Thanks,
Manish.

-----Original Message-----
From: Manish K Bafna
Sent: Tuesday, April 07, 2009 6:45 PM
To: camel-user@activemq. apache. org ([hidden email])
Subject: Multiple consumers getting created in custom endpoint

Hi,
I am creating my own custom endpoint using Camel 1.5

public class AbcEndpoint extends DefaultEndpoint {
public Consumer createConsumer(Processor processor) throws Exception {
            Consumer c=new AbcConsumer(this,processor);
            return c;
      }
.....
}

public class AbcConsumer extends DefaultConsumer<DefaultExchange>
{
protected void doStart() throws Exception {..do something...}
protected void doStop() throws Exception {--do something--}
}

When is start the context for the 1st time, 1 consumer is created, when I stop it and start it again, createConsumer() is called 2 times and so on.
Do I have to do something to avoid this behavior. The problem is in the doStart() method of the Consumer, I am creating my own threads. Now since createConsumer() is being 2 times, doStart() is being called 2 times and multiple threads are being created.





Reply | Threaded
Open this post in threaded view
|

Re: RE: Multiple consumers getting created in custom endpoint

Bruno Borges
I think you should "kill" your threads on method doStop() or stop() of your  
consumer.

They are invoked when CamelContext is stopped.

Cheers,
Bruno Borges

On Apr 8, 2009 12:38am, Manish K Bafna <[hidden email]> wrote:
> The same is visible in JMS component too.

> Steps:

> 1. Create a route from JMS topic1 to JMS queue1

> 2. Start the context

> 3. Send 1 message to the topic.

> 4. The queue will also receive 1 message.

> 5. Stop the context

> 6. Start the context again

> 7. Send 1 message to the topic.

> 8. the same message will be seen in the queue 2 times when there should  
> be only 1.

> 9. Repeat the above steps and the number increases.



> Thanks,

> Manish.



> -----Original Message-----

> From: Manish K Bafna

> Sent: Tuesday, April 07, 2009 6:45 PM

> To: camel-user@activemq. apache. org ([hidden email])

> Subject: Multiple consumers getting created in custom endpoint



> Hi,

> I am creating my own custom endpoint using Camel 1.5



> public class AbcEndpoint extends DefaultEndpoint {

> public Consumer createConsumer(Processor processor) throws Exception {

> Consumer c=new AbcConsumer(this,processor);

> return c;

> }

> .....

> }



> public class AbcConsumer extends DefaultConsumer

> {

> protected void doStart() throws Exception {..do something...}

> protected void doStop() throws Exception {--do something--}

> }



> When is start the context for the 1st time, 1 consumer is created, when I  
> stop it and start it again, createConsumer() is called 2 times and so on.

> Do I have to do something to avoid this behavior. The problem is in the  
> doStart() method of the Consumer, I am creating my own threads. Now since  
> createConsumer() is being 2 times, doStart() is being called 2 times and  
> multiple threads are being created.











Reply | Threaded
Open this post in threaded view
|

Re: RE: Multiple consumers getting created in custom endpoint

Claus Ibsen-2
Hi

I would suggest to use the JDK concurrency stuff for spawning threads.

See for instance the SedaConsumer
https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java


On Wed, Apr 8, 2009 at 4:53 PM,  <[hidden email]> wrote:

> I think you should "kill" your threads on method doStop() or stop() of your
> consumer.
>
> They are invoked when CamelContext is stopped.
>
> Cheers,
> Bruno Borges
>
> On Apr 8, 2009 12:38am, Manish K Bafna <[hidden email]> wrote:
>>
>> The same is visible in JMS component too.
>
>> Steps:
>
>> 1. Create a route from JMS topic1 to JMS queue1
>
>> 2. Start the context
>
>> 3. Send 1 message to the topic.
>
>> 4. The queue will also receive 1 message.
>
>> 5. Stop the context
>
>> 6. Start the context again
>
>> 7. Send 1 message to the topic.
>
>> 8. the same message will be seen in the queue 2 times when there should be
>> only 1.
>
>> 9. Repeat the above steps and the number increases.
>
>
>
>> Thanks,
>
>> Manish.
>
>
>
>> -----Original Message-----
>
>> From: Manish K Bafna
>
>> Sent: Tuesday, April 07, 2009 6:45 PM
>
>> To: camel-user@activemq. apache. org ([hidden email])
>
>> Subject: Multiple consumers getting created in custom endpoint
>
>
>
>> Hi,
>
>> I am creating my own custom endpoint using Camel 1.5
>
>
>
>> public class AbcEndpoint extends DefaultEndpoint {
>
>> public Consumer createConsumer(Processor processor) throws Exception {
>
>> Consumer c=new AbcConsumer(this,processor);
>
>> return c;
>
>> }
>
>> .....
>
>> }
>
>
>
>> public class AbcConsumer extends DefaultConsumer
>
>> {
>
>> protected void doStart() throws Exception {..do something...}
>
>> protected void doStop() throws Exception {--do something--}
>
>> }
>
>
>
>> When is start the context for the 1st time, 1 consumer is created, when I
>> stop it and start it again, createConsumer() is called 2 times and so on.
>
>> Do I have to do something to avoid this behavior. The problem is in the
>> doStart() method of the Consumer, I am creating my own threads. Now since
>> createConsumer() is being 2 times, doStart() is being called 2 times and
>> multiple threads are being created.
>
>
>
>
>
>
>
>
>
>
>
>



--
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Apache Camel Reference Card:
http://refcardz.dzone.com/refcardz/enterprise-integration
Reply | Threaded
Open this post in threaded view
|

RE: RE: Multiple consumers getting created in custom endpoint

Manish K Bafna
I guess there was an issue with Camel 1.5.
When starting the context, the routes are added in the list.
This route list is not cleared during stop.
So when the next time, the same context is started again, the routes gets added to the list again thereby duplication.

I solved the issue by clearing the route list during the stop of the context.

Thanks,
Manish.

-----Original Message-----
From: Claus Ibsen [mailto:[hidden email]]
Sent: Wednesday, April 08, 2009 8:39 PM
To: [hidden email]
Subject: Re: RE: Multiple consumers getting created in custom endpoint

Hi

I would suggest to use the JDK concurrency stuff for spawning threads.

See for instance the SedaConsumer
https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java


On Wed, Apr 8, 2009 at 4:53 PM,  <[hidden email]> wrote:

> I think you should "kill" your threads on method doStop() or stop() of your
> consumer.
>
> They are invoked when CamelContext is stopped.
>
> Cheers,
> Bruno Borges
>
> On Apr 8, 2009 12:38am, Manish K Bafna <[hidden email]> wrote:
>>
>> The same is visible in JMS component too.
>
>> Steps:
>
>> 1. Create a route from JMS topic1 to JMS queue1
>
>> 2. Start the context
>
>> 3. Send 1 message to the topic.
>
>> 4. The queue will also receive 1 message.
>
>> 5. Stop the context
>
>> 6. Start the context again
>
>> 7. Send 1 message to the topic.
>
>> 8. the same message will be seen in the queue 2 times when there should be
>> only 1.
>
>> 9. Repeat the above steps and the number increases.
>
>
>
>> Thanks,
>
>> Manish.
>
>
>
>> -----Original Message-----
>
>> From: Manish K Bafna
>
>> Sent: Tuesday, April 07, 2009 6:45 PM
>
>> To: camel-user@activemq. apache. org ([hidden email])
>
>> Subject: Multiple consumers getting created in custom endpoint
>
>
>
>> Hi,
>
>> I am creating my own custom endpoint using Camel 1.5
>
>
>
>> public class AbcEndpoint extends DefaultEndpoint {
>
>> public Consumer createConsumer(Processor processor) throws Exception {
>
>> Consumer c=new AbcConsumer(this,processor);
>
>> return c;
>
>> }
>
>> .....
>
>> }
>
>
>
>> public class AbcConsumer extends DefaultConsumer
>
>> {
>
>> protected void doStart() throws Exception {..do something...}
>
>> protected void doStop() throws Exception {--do something--}
>
>> }
>
>
>
>> When is start the context for the 1st time, 1 consumer is created, when I
>> stop it and start it again, createConsumer() is called 2 times and so on.
>
>> Do I have to do something to avoid this behavior. The problem is in the
>> doStart() method of the Consumer, I am creating my own threads. Now since
>> createConsumer() is being 2 times, doStart() is being called 2 times and
>> multiple threads are being created.
>
>
>
>
>
>
>
>
>
>
>
>



--
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Apache Camel Reference Card:
http://refcardz.dzone.com/refcardz/enterprise-integration
Reply | Threaded
Open this post in threaded view
|

Re: RE: Multiple consumers getting created in custom endpoint

Claus Ibsen-2
Hi

Have you tried with 2.0? Would be interresting to know if this issue
exists in 2.0 as well?


On Thu, Apr 9, 2009 at 6:21 AM, Manish K Bafna
<[hidden email]> wrote:

> I guess there was an issue with Camel 1.5.
> When starting the context, the routes are added in the list.
> This route list is not cleared during stop.
> So when the next time, the same context is started again, the routes gets added to the list again thereby duplication.
>
> I solved the issue by clearing the route list during the stop of the context.
>
> Thanks,
> Manish.
>
> -----Original Message-----
> From: Claus Ibsen [mailto:[hidden email]]
> Sent: Wednesday, April 08, 2009 8:39 PM
> To: [hidden email]
> Subject: Re: RE: Multiple consumers getting created in custom endpoint
>
> Hi
>
> I would suggest to use the JDK concurrency stuff for spawning threads.
>
> See for instance the SedaConsumer
> https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java
>
>
> On Wed, Apr 8, 2009 at 4:53 PM,  <[hidden email]> wrote:
>> I think you should "kill" your threads on method doStop() or stop() of your
>> consumer.
>>
>> They are invoked when CamelContext is stopped.
>>
>> Cheers,
>> Bruno Borges
>>
>> On Apr 8, 2009 12:38am, Manish K Bafna <[hidden email]> wrote:
>>>
>>> The same is visible in JMS component too.
>>
>>> Steps:
>>
>>> 1. Create a route from JMS topic1 to JMS queue1
>>
>>> 2. Start the context
>>
>>> 3. Send 1 message to the topic.
>>
>>> 4. The queue will also receive 1 message.
>>
>>> 5. Stop the context
>>
>>> 6. Start the context again
>>
>>> 7. Send 1 message to the topic.
>>
>>> 8. the same message will be seen in the queue 2 times when there should be
>>> only 1.
>>
>>> 9. Repeat the above steps and the number increases.
>>
>>
>>
>>> Thanks,
>>
>>> Manish.
>>
>>
>>
>>> -----Original Message-----
>>
>>> From: Manish K Bafna
>>
>>> Sent: Tuesday, April 07, 2009 6:45 PM
>>
>>> To: camel-user@activemq. apache. org ([hidden email])
>>
>>> Subject: Multiple consumers getting created in custom endpoint
>>
>>
>>
>>> Hi,
>>
>>> I am creating my own custom endpoint using Camel 1.5
>>
>>
>>
>>> public class AbcEndpoint extends DefaultEndpoint {
>>
>>> public Consumer createConsumer(Processor processor) throws Exception {
>>
>>> Consumer c=new AbcConsumer(this,processor);
>>
>>> return c;
>>
>>> }
>>
>>> .....
>>
>>> }
>>
>>
>>
>>> public class AbcConsumer extends DefaultConsumer
>>
>>> {
>>
>>> protected void doStart() throws Exception {..do something...}
>>
>>> protected void doStop() throws Exception {--do something--}
>>
>>> }
>>
>>
>>
>>> When is start the context for the 1st time, 1 consumer is created, when I
>>> stop it and start it again, createConsumer() is called 2 times and so on.
>>
>>> Do I have to do something to avoid this behavior. The problem is in the
>>> doStart() method of the Consumer, I am creating my own threads. Now since
>>> createConsumer() is being 2 times, doStart() is being called 2 times and
>>> multiple threads are being created.
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
> Apache Camel Reference Card:
> http://refcardz.dzone.com/refcardz/enterprise-integration
>



--
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Apache Camel Reference Card:
http://refcardz.dzone.com/refcardz/enterprise-integration
Reply | Threaded
Open this post in threaded view
|

Re: Multiple consumers getting created in custom endpoint

Willem.Jiang
Administrator
In reply to this post by Manish K Bafna
Hi Manish,

Please feel free to create a JIRA[1] ticket for it.
I just went through the code and can confirm your finding.

BTW there are some changes in the Camel 2.0 about starting and stoping
the RouteDefinintions. Not sure if it is resolved by Camel 2.0.

[1]https://issues.apache.org/activemq/browse/CAMEL

Willem

Manish K Bafna wrote:

> I guess there was an issue with Camel 1.5.
> When starting the context, the routes are added in the list.
> This route list is not cleared during stop.
> So when the next time, the same context is started again, the routes gets added to the list again thereby duplication.
>
> I solved the issue by clearing the route list during the stop of the context.
>
> Thanks,
> Manish.
>
> -----Original Message-----
> From: Claus Ibsen [mailto:[hidden email]]
> Sent: Wednesday, April 08, 2009 8:39 PM
> To: [hidden email]
> Subject: Re: RE: Multiple consumers getting created in custom endpoint
>
> Hi
>
> I would suggest to use the JDK concurrency stuff for spawning threads.
>
> See for instance the SedaConsumer
> https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java
>
>
> On Wed, Apr 8, 2009 at 4:53 PM,  <[hidden email]> wrote:
>> I think you should "kill" your threads on method doStop() or stop() of your
>> consumer.
>>
>> They are invoked when CamelContext is stopped.
>>
>> Cheers,
>> Bruno Borges
>>
>> On Apr 8, 2009 12:38am, Manish K Bafna <[hidden email]> wrote:
>>> The same is visible in JMS component too.
>>> Steps:
>>> 1. Create a route from JMS topic1 to JMS queue1
>>> 2. Start the context
>>> 3. Send 1 message to the topic.
>>> 4. The queue will also receive 1 message.
>>> 5. Stop the context
>>> 6. Start the context again
>>> 7. Send 1 message to the topic.
>>> 8. the same message will be seen in the queue 2 times when there should be
>>> only 1.
>>> 9. Repeat the above steps and the number increases.
>>
>>
>>> Thanks,
>>> Manish.
>>
>>
>>> -----Original Message-----
>>> From: Manish K Bafna
>>> Sent: Tuesday, April 07, 2009 6:45 PM
>>> To: camel-user@activemq. apache. org ([hidden email])
>>> Subject: Multiple consumers getting created in custom endpoint
>>
>>
>>> Hi,
>>> I am creating my own custom endpoint using Camel 1.5
>>
>>
>>> public class AbcEndpoint extends DefaultEndpoint {
>>> public Consumer createConsumer(Processor processor) throws Exception {
>>> Consumer c=new AbcConsumer(this,processor);
>>> return c;
>>> }
>>> .....
>>> }
>>
>>
>>> public class AbcConsumer extends DefaultConsumer
>>> {
>>> protected void doStart() throws Exception {..do something...}
>>> protected void doStop() throws Exception {--do something--}
>>> }
>>
>>
>>> When is start the context for the 1st time, 1 consumer is created, when I
>>> stop it and start it again, createConsumer() is called 2 times and so on.
>>> Do I have to do something to avoid this behavior. The problem is in the
>>> doStart() method of the Consumer, I am creating my own threads. Now since
>>> createConsumer() is being 2 times, doStart() is being called 2 times and
>>> multiple threads are being created.
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Multiple consumers getting created in custom endpoint

Willem.Jiang
Administrator
Hi Manish,

I just created a JIRA[1] for this issue, and committed a quick fix for it.
I also did a quick fix for the Camel trunk, please feel free to verify
it with Camel 2.0.

We will get it out soon, maybe this Quarter :)

[1] https://issues.apache.org/activemq/browse/CAMEL-1544

Willem
Willem Jiang wrote:

> Hi Manish,
>
> Please feel free to create a JIRA[1] ticket for it.
> I just went through the code and can confirm your finding.
>
> BTW there are some changes in the Camel 2.0 about starting and stoping
> the RouteDefinintions. Not sure if it is resolved by Camel 2.0.
>
> [1]https://issues.apache.org/activemq/browse/CAMEL
>
> Willem
>
> Manish K Bafna wrote:
>> I guess there was an issue with Camel 1.5.
>> When starting the context, the routes are added in the list.
>> This route list is not cleared during stop.
>> So when the next time, the same context is started again, the routes gets added to the list again thereby duplication.
>>
>> I solved the issue by clearing the route list during the stop of the context.
>>
>> Thanks,
>> Manish.
>>
>> -----Original Message-----
>> From: Claus Ibsen [mailto:[hidden email]]
>> Sent: Wednesday, April 08, 2009 8:39 PM
>> To: [hidden email]
>> Subject: Re: RE: Multiple consumers getting created in custom endpoint
>>
>> Hi
>>
>> I would suggest to use the JDK concurrency stuff for spawning threads.
>>
>> See for instance the SedaConsumer
>> https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java
>>
>>
>> On Wed, Apr 8, 2009 at 4:53 PM,  <[hidden email]> wrote:
>>> I think you should "kill" your threads on method doStop() or stop() of your
>>> consumer.
>>>
>>> They are invoked when CamelContext is stopped.
>>>
>>> Cheers,
>>> Bruno Borges
>>>
>>> On Apr 8, 2009 12:38am, Manish K Bafna <[hidden email]> wrote:
>>>> The same is visible in JMS component too.
>>>> Steps:
>>>> 1. Create a route from JMS topic1 to JMS queue1
>>>> 2. Start the context
>>>> 3. Send 1 message to the topic.
>>>> 4. The queue will also receive 1 message.
>>>> 5. Stop the context
>>>> 6. Start the context again
>>>> 7. Send 1 message to the topic.
>>>> 8. the same message will be seen in the queue 2 times when there should be
>>>> only 1.
>>>> 9. Repeat the above steps and the number increases.
>>>
>>>> Thanks,
>>>> Manish.
>>>
>>>> -----Original Message-----
>>>> From: Manish K Bafna
>>>> Sent: Tuesday, April 07, 2009 6:45 PM
>>>> To: camel-user@activemq. apache. org ([hidden email])
>>>> Subject: Multiple consumers getting created in custom endpoint
>>>
>>>> Hi,
>>>> I am creating my own custom endpoint using Camel 1.5
>>>
>>>> public class AbcEndpoint extends DefaultEndpoint {
>>>> public Consumer createConsumer(Processor processor) throws Exception {
>>>> Consumer c=new AbcConsumer(this,processor);
>>>> return c;
>>>> }
>>>> .....
>>>> }
>>>
>>>> public class AbcConsumer extends DefaultConsumer
>>>> {
>>>> protected void doStart() throws Exception {..do something...}
>>>> protected void doStop() throws Exception {--do something--}
>>>> }
>>>
>>>> When is start the context for the 1st time, 1 consumer is created, when I
>>>> stop it and start it again, createConsumer() is called 2 times and so on.
>>>> Do I have to do something to avoid this behavior. The problem is in the
>>>> doStart() method of the Consumer, I am creating my own threads. Now since
>>>> createConsumer() is being 2 times, doStart() is being called 2 times and
>>>> multiple threads are being created.
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
>
>