You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "jayson.minard" <ja...@gmail.com> on 2008/09/17 18:46:08 UTC
ProducerTemplate and ActiveMQ component seems to leak threads
With a route such as:
from("activemq:queue:test.input").process(new
TestProcessor("activemq:queue:test.output"));
And in the TestProcessor class, if we do something like:
// outEndPoint is derived from the constructor parameter and is
"activemq:queue:test.output.something"
Message msg = exchange.getIn();
ProducerTemplate producer =
exchange.getContext().createProducerTemplate();
producer.sendBodyAndHeaders(outEndPoint, msg.getBody(),
msg.getHeaders());
It leaks threads and holds open ActiveMQ sessions endlessly. We have the
ActiveMQ component configured and pooling is on, and all other routes do not
leak threads other than when we use ProducerTemplate.
Is there something different needing to be done to make sure the pooling in
ActiveMQ component is used when ProducerTemplate is the source of messages?
Thanks for any help or advice...
-- Jayson
--
View this message in context: http://www.nabble.com/ProducerTemplate-and-ActiveMQ-component-seems-to-leak-threads-tp19536417s22882p19536417.html
Sent from the Camel - Users mailing list archive at Nabble.com.
RE: [SPAM] Re: ProducerTemplate and ActiveMQ component seems to leak threads
Posted by Claus Ibsen <ci...@silverbullet.dk>.
Hi Jason
Thanks for the feedback. I have updated the release note for 1.4 with your suggestions about the ProducerTemplate.
Med venlig hilsen
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk
-----Original Message-----
From: jayson.minard [mailto:jayson.minard@gmail.com]
Sent: 18. september 2008 19:24
To: camel-user@activemq.apache.org
Subject: [SPAM] Re: ProducerTemplate and ActiveMQ component seems to leak threads
Thanks James! (We are on ActiveMQ 5.1.0 and Camel 1.4 by the way)
There is guidance in the 1.4 release notes "From Camel 1.4.0 on the
ProducerTemplate must be retrieved from the CamelContext. You can then use
it the same way as before." which could lead people down the wrong path and
not much pointing to the stop method, although the fact it is there should
draw attention.
So we'll now allocate a DefaultProducerTemplate passing in the context
within Spring instead and keep that instance around.
Thanks for the help!
-- Jayson
James.Strachan wrote:
>
> 2008/9/17 jayson.minard <ja...@gmail.com>:
>>
>> With a route such as:
>>
>>
>> from("activemq:queue:test.input").process(new
>> TestProcessor("activemq:queue:test.output"));
>>
>>
>> And in the TestProcessor class, if we do something like:
>>
>>
>> // outEndPoint is derived from the constructor parameter and is
>> "activemq:queue:test.output.something"
>> Message msg = exchange.getIn();
>> ProducerTemplate producer =
>> exchange.getContext().createProducerTemplate();
>> producer.sendBodyAndHeaders(outEndPoint, msg.getBody(),
>> msg.getHeaders());
>>
>>
>> It leaks threads and holds open ActiveMQ sessions endlessly.
>
> You are not meant to create a ProducerTemplate for each message
> invocation; you are meant to create a single instance on startup and
> keep it around. Also when you have finished using the
> ProducerTemplate you should call the stop() method to close down all
> the resources it has been using.
>
> Its better to either explicitly create one on startup or get your IoC
> container (Spring/Guice) to inject it into your Processor
>
> --
> James
> -------
> http://macstrac.blogspot.com/
>
> Open Source Integration
> http://open.iona.com
>
>
--
View this message in context: http://www.nabble.com/ProducerTemplate-and-ActiveMQ-component-seems-to-leak-threads-tp19536417s22882p19557800.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: ProducerTemplate and ActiveMQ component seems to leak threads
Posted by "jayson.minard" <ja...@gmail.com>.
Thanks James! (We are on ActiveMQ 5.1.0 and Camel 1.4 by the way)
There is guidance in the 1.4 release notes "From Camel 1.4.0 on the
ProducerTemplate must be retrieved from the CamelContext. You can then use
it the same way as before." which could lead people down the wrong path and
not much pointing to the stop method, although the fact it is there should
draw attention.
So we'll now allocate a DefaultProducerTemplate passing in the context
within Spring instead and keep that instance around.
Thanks for the help!
-- Jayson
James.Strachan wrote:
>
> 2008/9/17 jayson.minard <ja...@gmail.com>:
>>
>> With a route such as:
>>
>>
>> from("activemq:queue:test.input").process(new
>> TestProcessor("activemq:queue:test.output"));
>>
>>
>> And in the TestProcessor class, if we do something like:
>>
>>
>> // outEndPoint is derived from the constructor parameter and is
>> "activemq:queue:test.output.something"
>> Message msg = exchange.getIn();
>> ProducerTemplate producer =
>> exchange.getContext().createProducerTemplate();
>> producer.sendBodyAndHeaders(outEndPoint, msg.getBody(),
>> msg.getHeaders());
>>
>>
>> It leaks threads and holds open ActiveMQ sessions endlessly.
>
> You are not meant to create a ProducerTemplate for each message
> invocation; you are meant to create a single instance on startup and
> keep it around. Also when you have finished using the
> ProducerTemplate you should call the stop() method to close down all
> the resources it has been using.
>
> Its better to either explicitly create one on startup or get your IoC
> container (Spring/Guice) to inject it into your Processor
>
> --
> James
> -------
> http://macstrac.blogspot.com/
>
> Open Source Integration
> http://open.iona.com
>
>
--
View this message in context: http://www.nabble.com/ProducerTemplate-and-ActiveMQ-component-seems-to-leak-threads-tp19536417s22882p19557800.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: ProducerTemplate and ActiveMQ component seems to leak threads
Posted by James Strachan <ja...@gmail.com>.
Done :)
http://cwiki.apache.org/CAMEL/why-does-camel-use-too-many-threads-with-producertemplate.html
2008/9/18 James Strachan <ja...@gmail.com>:
> 2008/9/17 jayson.minard <ja...@gmail.com>:
>>
>> With a route such as:
>>
>>
>> from("activemq:queue:test.input").process(new
>> TestProcessor("activemq:queue:test.output"));
>>
>>
>> And in the TestProcessor class, if we do something like:
>>
>>
>> // outEndPoint is derived from the constructor parameter and is
>> "activemq:queue:test.output.something"
>> Message msg = exchange.getIn();
>> ProducerTemplate producer =
>> exchange.getContext().createProducerTemplate();
>> producer.sendBodyAndHeaders(outEndPoint, msg.getBody(),
>> msg.getHeaders());
>>
>>
>> It leaks threads and holds open ActiveMQ sessions endlessly.
>
> You are not meant to create a ProducerTemplate for each message
> invocation; you are meant to create a single instance on startup and
> keep it around. Also when you have finished using the
> ProducerTemplate you should call the stop() method to close down all
> the resources it has been using.
>
> Its better to either explicitly create one on startup or get your IoC
> container (Spring/Guice) to inject it into your Processor
>
> --
> James
> -------
> http://macstrac.blogspot.com/
>
> Open Source Integration
> http://open.iona.com
>
--
James
-------
http://macstrac.blogspot.com/
Open Source Integration
http://open.iona.com
RE: [SPAM] Re: ProducerTemplate and ActiveMQ component seems to leak threads
Posted by Claus Ibsen <ci...@silverbullet.dk>.
James, great answer
Please add a FAQ entry about this ;)
Med venlig hilsen
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk
-----Original Message-----
From: James Strachan [mailto:james.strachan@gmail.com]
Sent: 18. september 2008 10:52
To: camel-user@activemq.apache.org
Subject: [SPAM] Re: ProducerTemplate and ActiveMQ component seems to leak threads
2008/9/17 jayson.minard <ja...@gmail.com>:
>
> With a route such as:
>
>
> from("activemq:queue:test.input").process(new
> TestProcessor("activemq:queue:test.output"));
>
>
> And in the TestProcessor class, if we do something like:
>
>
> // outEndPoint is derived from the constructor parameter and is
> "activemq:queue:test.output.something"
> Message msg = exchange.getIn();
> ProducerTemplate producer =
> exchange.getContext().createProducerTemplate();
> producer.sendBodyAndHeaders(outEndPoint, msg.getBody(),
> msg.getHeaders());
>
>
> It leaks threads and holds open ActiveMQ sessions endlessly.
You are not meant to create a ProducerTemplate for each message
invocation; you are meant to create a single instance on startup and
keep it around. Also when you have finished using the
ProducerTemplate you should call the stop() method to close down all
the resources it has been using.
Its better to either explicitly create one on startup or get your IoC
container (Spring/Guice) to inject it into your Processor
--
James
-------
http://macstrac.blogspot.com/
Open Source Integration
http://open.iona.com
Re: ProducerTemplate and ActiveMQ component seems to leak threads
Posted by James Strachan <ja...@gmail.com>.
2008/9/17 jayson.minard <ja...@gmail.com>:
>
> With a route such as:
>
>
> from("activemq:queue:test.input").process(new
> TestProcessor("activemq:queue:test.output"));
>
>
> And in the TestProcessor class, if we do something like:
>
>
> // outEndPoint is derived from the constructor parameter and is
> "activemq:queue:test.output.something"
> Message msg = exchange.getIn();
> ProducerTemplate producer =
> exchange.getContext().createProducerTemplate();
> producer.sendBodyAndHeaders(outEndPoint, msg.getBody(),
> msg.getHeaders());
>
>
> It leaks threads and holds open ActiveMQ sessions endlessly.
You are not meant to create a ProducerTemplate for each message
invocation; you are meant to create a single instance on startup and
keep it around. Also when you have finished using the
ProducerTemplate you should call the stop() method to close down all
the resources it has been using.
Its better to either explicitly create one on startup or get your IoC
container (Spring/Guice) to inject it into your Processor
--
James
-------
http://macstrac.blogspot.com/
Open Source Integration
http://open.iona.com
RE: ProducerTemplate and ActiveMQ component seems to leak threads
Posted by Claus Ibsen <ci...@silverbullet.dk>.
Hi
Not really. The template is at the end using the same code as the route builders does.
What versions of the products are you using?
Can you provide a small sample application that has this flaw?
Med venlig hilsen
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk
-----Original Message-----
From: jayson.minard [mailto:jayson.minard@gmail.com]
Sent: 17. september 2008 18:46
To: camel-user@activemq.apache.org
Subject: ProducerTemplate and ActiveMQ component seems to leak threads
With a route such as:
from("activemq:queue:test.input").process(new
TestProcessor("activemq:queue:test.output"));
And in the TestProcessor class, if we do something like:
// outEndPoint is derived from the constructor parameter and is
"activemq:queue:test.output.something"
Message msg = exchange.getIn();
ProducerTemplate producer =
exchange.getContext().createProducerTemplate();
producer.sendBodyAndHeaders(outEndPoint, msg.getBody(),
msg.getHeaders());
It leaks threads and holds open ActiveMQ sessions endlessly. We have the
ActiveMQ component configured and pooling is on, and all other routes do not
leak threads other than when we use ProducerTemplate.
Is there something different needing to be done to make sure the pooling in
ActiveMQ component is used when ProducerTemplate is the source of messages?
Thanks for any help or advice...
-- Jayson
--
View this message in context: http://www.nabble.com/ProducerTemplate-and-ActiveMQ-component-seems-to-leak-threads-tp19536417s22882p19536417.html
Sent from the Camel - Users mailing list archive at Nabble.com.