You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by elena <el...@hotmail.com> on 2014/05/19 19:05:09 UTC

ProducerTemplate creates too much threads

Hi,

Our company use ActiveMQ 5.6.0 and Camel 2.10.0. We noticed that
ProducerTemplate creates too much threads 
TemporaryQueueReplyManager[temporary]-1 and
JmsReplyManagerTimeoutChecker[queueName] when sending requests. The threads
have a waiting status. This causes a problem on our production system
deployed on Linux PC. The system has dozens of queues and dozens of clients
sending requests to get data. Is there a way to eliminate the number of
these threads? Why they are not stopped when producer template received the
response?

Below is the excerpt from the stack trace:

org.apache.camel.ProducerTemplate.requestBody(java.lang.String,
java.lang.Object)
com.sick.service.ObjectDataService.findSortListByTunnel(java.lang.String,
java.lang.Integer)
......

As recommended, we use only one camel template:

<camel:camelContext id="ent-camel-client"
xmlns="http://camel.apache.org/schema/spring">
	<camel:contextScan />
	<camel:jmxAgent id="agent" createConnector="false" />
	<camel:template id="camelTemplate" />
</camel:camelContext>

Thanks,
Elena



--
View this message in context: http://camel.465427.n5.nabble.com/ProducerTemplate-creates-too-much-threads-tp5751299.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ProducerTemplate creates too much threads

Posted by elena <el...@hotmail.com>.
Thanks.



--
View this message in context: http://camel.465427.n5.nabble.com/ProducerTemplate-creates-too-much-threads-tp5751299p5751438.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ProducerTemplate creates too much threads

Posted by Claus Ibsen <cl...@gmail.com>.
You can use the addService api on CamelContext - see its javadoc

On Tue, Oct 20, 2015 at 1:55 PM, Shylendran C <sh...@gmail.com> wrote:
> Thanks for your reply.
> So, just want to confirm - no need to put the start() and stop() for each
> thread, is that correct?
> And,  our application will be running for ever (untill we manually kill the
> process), so I am not sure where to put the stop() method. Any suggestions?
>
> Thanks again,
> Shylendran.C
>
> On Tue, Oct 20, 2015 at 1:06 AM, Claus Ibsen <cl...@gmail.com> wrote:
>
>> Dont start / stop it all the time, create it once and reuse it, and
>> stop it when you stop your app.
>>
>> On Tue, Oct 20, 2015 at 6:17 AM, shylendran.c <sh...@gmail.com>
>> wrote:
>> > Hi,
>> > I am using camel-code-2.15.2.jar. I have a multi-threaded application
>> where
>> > I have to send message continuously and I am using
>> > org.apache.camel.ProducerTemplate. But since it is a multi-threaded, it
>> is
>> > breaking and getting the below exceptions. So, I've tried with 'static
>> > synchronized' where everything is working, but we can't go with 'static
>> > synchronized'. So looking for a solution.
>> > It is clear that the exception is happening when we have
>> > ProducerTemplate.start() and stop() when multi-threads are invoking
>> this. We
>> > have created only one instance of ProducerTemplate.
>> >
>> > Is there a way which I can check whether the producer template is already
>> > 'open' or 'stop'. I see few protected variables, and while debugging I
>> see
>> > exactly what I am looking.
>> > Please let me know your opinion on this.
>> >
>> > class RMThread implements Runnable {
>> >
>> > .......
>> > .........
>> > public void run() {
>> > if (producerTemp != null) {
>> >
>> > producerTemp.start();
>> > producerTemp.sendBodyAndHeaders("zzzz", "", map);
>> > producerTemp.stop();
>> > .....
>> > ......
>> > }
>> > }
>> >
>> > public class MainClass {
>> > ....
>> > ProducerTemplate producerTemplate = null;
>> > producerTemplate = configureRoutes.getContext().createProducerTemplate();
>> >
>> > ServerSocket ss = new ServerSocket(111
>> > while (true) {
>> > new Thread(new RMThread(ss.accept(), log, producerTemplate,
>> > producerTemplate_sendTransferMetrics)).start();
>> > ....
>> > }
>> >
>> >
>> > Exceptions::
>> > org.apache.camel.CamelExecutionException: Exception occurred during
>> > execution on the exchange: Exchange[Message: ]
>> >         at
>> >
>> org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1635)
>> > ....
>> > Caused by: java.lang.IllegalStateException: Pool not open
>> >         at
>> >
>> org.apache.commons.pool.BaseObjectPool.assertOpen(BaseObjectPool.java:140)
>> > ...
>> > ....
>> >
>> > Thanks,
>> > Shylendran.C
>> >
>> >
>> >
>> >
>> > --
>> > View this message in context:
>> http://camel.465427.n5.nabble.com/ProducerTemplate-creates-too-much-threads-tp5751299p5772885.html
>> > Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> http://davsclaus.com @davsclaus
>> Camel in Action 2nd edition:
>> https://www.manning.com/books/camel-in-action-second-edition
>>



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2nd edition:
https://www.manning.com/books/camel-in-action-second-edition

Re: ProducerTemplate creates too much threads

Posted by Shylendran C <sh...@gmail.com>.
Thanks for your reply.
So, just want to confirm - no need to put the start() and stop() for each
thread, is that correct?
And,  our application will be running for ever (untill we manually kill the
process), so I am not sure where to put the stop() method. Any suggestions?

Thanks again,
Shylendran.C

On Tue, Oct 20, 2015 at 1:06 AM, Claus Ibsen <cl...@gmail.com> wrote:

> Dont start / stop it all the time, create it once and reuse it, and
> stop it when you stop your app.
>
> On Tue, Oct 20, 2015 at 6:17 AM, shylendran.c <sh...@gmail.com>
> wrote:
> > Hi,
> > I am using camel-code-2.15.2.jar. I have a multi-threaded application
> where
> > I have to send message continuously and I am using
> > org.apache.camel.ProducerTemplate. But since it is a multi-threaded, it
> is
> > breaking and getting the below exceptions. So, I've tried with 'static
> > synchronized' where everything is working, but we can't go with 'static
> > synchronized'. So looking for a solution.
> > It is clear that the exception is happening when we have
> > ProducerTemplate.start() and stop() when multi-threads are invoking
> this. We
> > have created only one instance of ProducerTemplate.
> >
> > Is there a way which I can check whether the producer template is already
> > 'open' or 'stop'. I see few protected variables, and while debugging I
> see
> > exactly what I am looking.
> > Please let me know your opinion on this.
> >
> > class RMThread implements Runnable {
> >
> > .......
> > .........
> > public void run() {
> > if (producerTemp != null) {
> >
> > producerTemp.start();
> > producerTemp.sendBodyAndHeaders("zzzz", "", map);
> > producerTemp.stop();
> > .....
> > ......
> > }
> > }
> >
> > public class MainClass {
> > ....
> > ProducerTemplate producerTemplate = null;
> > producerTemplate = configureRoutes.getContext().createProducerTemplate();
> >
> > ServerSocket ss = new ServerSocket(111
> > while (true) {
> > new Thread(new RMThread(ss.accept(), log, producerTemplate,
> > producerTemplate_sendTransferMetrics)).start();
> > ....
> > }
> >
> >
> > Exceptions::
> > org.apache.camel.CamelExecutionException: Exception occurred during
> > execution on the exchange: Exchange[Message: ]
> >         at
> >
> org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1635)
> > ....
> > Caused by: java.lang.IllegalStateException: Pool not open
> >         at
> >
> org.apache.commons.pool.BaseObjectPool.assertOpen(BaseObjectPool.java:140)
> > ...
> > ....
> >
> > Thanks,
> > Shylendran.C
> >
> >
> >
> >
> > --
> > View this message in context:
> http://camel.465427.n5.nabble.com/ProducerTemplate-creates-too-much-threads-tp5751299p5772885.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2nd edition:
> https://www.manning.com/books/camel-in-action-second-edition
>

Re: ProducerTemplate creates too much threads

Posted by Claus Ibsen <cl...@gmail.com>.
Dont start / stop it all the time, create it once and reuse it, and
stop it when you stop your app.

On Tue, Oct 20, 2015 at 6:17 AM, shylendran.c <sh...@gmail.com> wrote:
> Hi,
> I am using camel-code-2.15.2.jar. I have a multi-threaded application where
> I have to send message continuously and I am using
> org.apache.camel.ProducerTemplate. But since it is a multi-threaded, it is
> breaking and getting the below exceptions. So, I've tried with 'static
> synchronized' where everything is working, but we can't go with 'static
> synchronized'. So looking for a solution.
> It is clear that the exception is happening when we have
> ProducerTemplate.start() and stop() when multi-threads are invoking this. We
> have created only one instance of ProducerTemplate.
>
> Is there a way which I can check whether the producer template is already
> 'open' or 'stop'. I see few protected variables, and while debugging I see
> exactly what I am looking.
> Please let me know your opinion on this.
>
> class RMThread implements Runnable {
>
> .......
> .........
> public void run() {
> if (producerTemp != null) {
>
> producerTemp.start();
> producerTemp.sendBodyAndHeaders("zzzz", "", map);
> producerTemp.stop();
> .....
> ......
> }
> }
>
> public class MainClass {
> ....
> ProducerTemplate producerTemplate = null;
> producerTemplate = configureRoutes.getContext().createProducerTemplate();
>
> ServerSocket ss = new ServerSocket(111
> while (true) {
> new Thread(new RMThread(ss.accept(), log, producerTemplate,
> producerTemplate_sendTransferMetrics)).start();
> ....
> }
>
>
> Exceptions::
> org.apache.camel.CamelExecutionException: Exception occurred during
> execution on the exchange: Exchange[Message: ]
>         at
> org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1635)
> ....
> Caused by: java.lang.IllegalStateException: Pool not open
>         at
> org.apache.commons.pool.BaseObjectPool.assertOpen(BaseObjectPool.java:140)
> ...
> ....
>
> Thanks,
> Shylendran.C
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/ProducerTemplate-creates-too-much-threads-tp5751299p5772885.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2nd edition:
https://www.manning.com/books/camel-in-action-second-edition

Re: ProducerTemplate creates too much threads

Posted by "shylendran.c" <sh...@gmail.com>.
Hi,
I am using camel-code-2.15.2.jar. I have a multi-threaded application where
I have to send message continuously and I am using
org.apache.camel.ProducerTemplate. But since it is a multi-threaded, it is
breaking and getting the below exceptions. So, I've tried with 'static
synchronized' where everything is working, but we can't go with 'static
synchronized'. So looking for a solution.
It is clear that the exception is happening when we have
ProducerTemplate.start() and stop() when multi-threads are invoking this. We
have created only one instance of ProducerTemplate.

Is there a way which I can check whether the producer template is already
'open' or 'stop'. I see few protected variables, and while debugging I see
exactly what I am looking. 
Please let me know your opinion on this.

class RMThread implements Runnable {

.......
.........
public void run() {
if (producerTemp != null) {

producerTemp.start();
producerTemp.sendBodyAndHeaders("zzzz", "", map);
producerTemp.stop();
.....
......
}
}

public class MainClass {
....
ProducerTemplate producerTemplate = null;
producerTemplate = configureRoutes.getContext().createProducerTemplate();

ServerSocket ss = new ServerSocket(111
while (true) {
new Thread(new RMThread(ss.accept(), log, producerTemplate,
producerTemplate_sendTransferMetrics)).start();
....
}


Exceptions::
org.apache.camel.CamelExecutionException: Exception occurred during
execution on the exchange: Exchange[Message: ]
	at
org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1635)
....
Caused by: java.lang.IllegalStateException: Pool not open
	at
org.apache.commons.pool.BaseObjectPool.assertOpen(BaseObjectPool.java:140)
...
....

Thanks,
Shylendran.C




--
View this message in context: http://camel.465427.n5.nabble.com/ProducerTemplate-creates-too-much-threads-tp5751299p5772885.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ProducerTemplate creates too much threads

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

If you use dynamic request and response queues (eg use many queues
instead of few) and if those queues are not to be reused, then you
would need to close the resources when you are done.

So it would only make sense to reuse the producer template for queues
you want to reuse in the future.
And for one time usage only, then create a new template, and stop it after use.

Also Camel 2.10.x is a bit old, you may try upgrading as we fix stuff
in newer releases.


On Tue, May 20, 2014 at 8:00 PM, elena <el...@hotmail.com> wrote:
> Hi Claus,
>
> Thank you for the response.
>
> Our server is multithreaded web-application. It sends requests to the
> multiple endpoints in separate threads.
>
> Please see below the sample of the code.
>
> private ProducerTemplate camelTemplate;
>
> synchronized public List<HubRequest> executeMultipleQueries(final String[]
> hubUIDs, final QueryParameter[] params) {
>         for (String hubId : hubUIDs) {
>                 Runnable task = new Runnable() {
>             public void run() {
>                                 try {
>                                         Object resp = camelTemplate.requestBodyAndHeader(requestUri, params,
> "responseUri", responseUri);
>                                         ...
>                                 } catch () {
>                                         ...
>                                 }
>                         }
>                 }
>
>         }
> }
>
> What should we do in this case to release the ProducerTemplate resources?
>
> a) Start the service every time before the request and stop after the
> response have been received, for example:
>
> camelTemplate.start();
> Object resp = camelTemplate.requestBodyAndHeader(requestUri, params,
> "responseUri", responseUri);
> ....
> camelTemplate.stop();
>
> b) Or use multiple ProducerTemplates?
>
> What will be the best solution? Our server processes a lot of requests sent
> from the client application.
> Currently we use only one ProducerTemplate defined in the camelContext:
>
>
>         <camel:camelContext id="ent-camel-client"
> xmlns="http://camel.apache.org/schema/spring">
>                 <camel:contextScan />
>                 <camel:jmxAgent id="agent" createConnector="false" />
>                 <camel:template id="camelTemplate" />
>         </camel:camelContext>
>
> We will appreciate your recommendations.
>
> Thanks,
> Elena
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/ProducerTemplate-creates-too-much-threads-tp5751299p5751367.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: ProducerTemplate creates too much threads

Posted by elena <el...@hotmail.com>.
Hi Claus,

Thank you for the response.

Our server is multithreaded web-application. It sends requests to the
multiple endpoints in separate threads.

Please see below the sample of the code.

private ProducerTemplate camelTemplate;

synchronized public List<HubRequest> executeMultipleQueries(final String[]
hubUIDs, final QueryParameter[] params) {
	for (String hubId : hubUIDs) {
		Runnable task = new Runnable() {
            public void run() {
				try {
					Object resp = camelTemplate.requestBodyAndHeader(requestUri, params,
"responseUri", responseUri);
					...
				} catch () {
					...
				}
			}
		}
	
	}
}

What should we do in this case to release the ProducerTemplate resources?

a) Start the service every time before the request and stop after the
response have been received, for example:

camelTemplate.start();
Object resp = camelTemplate.requestBodyAndHeader(requestUri, params,
"responseUri", responseUri);
....
camelTemplate.stop();

b) Or use multiple ProducerTemplates? 

What will be the best solution? Our server processes a lot of requests sent
from the client application.
Currently we use only one ProducerTemplate defined in the camelContext:

	
	<camel:camelContext id="ent-camel-client"
xmlns="http://camel.apache.org/schema/spring">
		<camel:contextScan />
		<camel:jmxAgent id="agent" createConnector="false" />
		<camel:template id="camelTemplate" />
	</camel:camelContext>

We will appreciate your recommendations.

Thanks,
Elena



--
View this message in context: http://camel.465427.n5.nabble.com/ProducerTemplate-creates-too-much-threads-tp5751299p5751367.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ProducerTemplate creates too much threads

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

If you only need one time response, then stop the template after
usage. Otherwise it keeps resources "warn".

And see this FAQ too
http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html

On Mon, May 19, 2014 at 7:05 PM, elena <el...@hotmail.com> wrote:
> Hi,
>
> Our company use ActiveMQ 5.6.0 and Camel 2.10.0. We noticed that
> ProducerTemplate creates too much threads
> TemporaryQueueReplyManager[temporary]-1 and
> JmsReplyManagerTimeoutChecker[queueName] when sending requests. The threads
> have a waiting status. This causes a problem on our production system
> deployed on Linux PC. The system has dozens of queues and dozens of clients
> sending requests to get data. Is there a way to eliminate the number of
> these threads? Why they are not stopped when producer template received the
> response?
>
> Below is the excerpt from the stack trace:
>
> org.apache.camel.ProducerTemplate.requestBody(java.lang.String,
> java.lang.Object)
> com.sick.service.ObjectDataService.findSortListByTunnel(java.lang.String,
> java.lang.Integer)
> ......
>
> As recommended, we use only one camel template:
>
> <camel:camelContext id="ent-camel-client"
> xmlns="http://camel.apache.org/schema/spring">
>         <camel:contextScan />
>         <camel:jmxAgent id="agent" createConnector="false" />
>         <camel:template id="camelTemplate" />
> </camel:camelContext>
>
> Thanks,
> Elena
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/ProducerTemplate-creates-too-much-threads-tp5751299.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: ProducerTemplate creates too much threads

Posted by elena <el...@hotmail.com>.
Thanks for your reply Willem.

It was good to know about the configuring the cache.

But are you sure this is the answer to my question about the threads?

Elena





--
View this message in context: http://camel.465427.n5.nabble.com/ProducerTemplate-creates-too-much-threads-tp5751299p5751361.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ProducerTemplate creates too much threads

Posted by Brad Johnson <br...@mediadriver.com>.
It's extremely important to learn the EIPs available to you in Camel and
leverage them to the greatest extent possible.  They'll do a lot of the
heavy lifting.  You can use a CBR to send data to various routes or beans
based on some value in the data header or body, for example.

I handle SOAP requests all the time without using Processors.  As an
example of how this is easily accomplished look at this snippet of
blueprint.  It could be done in others as well.

<recipientList>
<simple>direct-vm:${header.operationName}</simple>
</recipientList>

The operation name there is set on the method of the SOAP interface or in
the WSDL (though I usually go code first.)

If you set up routes that are based on the operation name listening on that
then they will receive the message.  So here's a definition of an API and
I've decorated it for use in both the SOAP and REST endpoints.  (The REST
endpoints/uris in @Path are named incorrectly here as they should be noun
based but it gets the idea across.)

@WebMethod(operationName = "getFoo", action = "")
@GET
@Path("/resource/bar/{token}")
@Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
@Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_JSON})
public String getFoo(@WebParam Foo foo);
@WebMethod(operationName = "addFoo", action = "")
@PUT
@Path("/resource/foo/{token}")
@Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
@Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_JSON})
public void addFoo(@WebParam Foo foo);

So we have this in our SOAP and REST related camel contexts/routes.
<recipientList>
<simple>direct-vm:${header.operationName}</simple>
</recipientList>



<camelContext id="Foo-SOAP-context" xmlns="
http://camel.apache.org/schema/blueprint">

<route id="Foo-SOAP">
<from uri="cxf:bean:fooSOAPEndpoint" />

<transform>
<simple>${body[0]}</simple>
</transform>

<recipientList>
<simple>direct-vm:${header.operationName}</simple>
</recipientList>
</route>
</camelContext>

In the same or different bundle you can then add:

<route id="fooAddRoute">
       <from uri="direct-vm:addFoo">
       <bean ref="fooAddHandler"/>
        <to ...whoever is next or if nothing, then return something from
the handler or if the SOAP/REST endpoint is void return nothing.

</route>

Now whether the request is coming in through SOAP or REST it is will invoke
the addFoo route, unmarshal the object into a Foo object, and send it to
the route.

No need to use Processors, ProducerTemplates or anything else.  Just let
Camel do the work for you and learn the EIPs!

On Sun, Sep 11, 2016 at 12:19 AM, niteshjain <ni...@gmail.com>
wrote:

> I'm using Processor interface, to handle the incoming SOAP request from the
> Exchange and apply some business logic on it, Based on the business logic I
> wanted to invoke different camel routes (defined in camel context xml),
> hence ProducerTemplate to invoke different camel routes.
>
> Regards,
> Nithesh
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.
> com/ProducerTemplate-creates-too-much-threads-tp5751299p5787445.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: ProducerTemplate creates too much threads

Posted by niteshjain <ni...@gmail.com>.
I'm using Processor interface, to handle the incoming SOAP request from the
Exchange and apply some business logic on it, Based on the business logic I
wanted to invoke different camel routes (defined in camel context xml),
hence ProducerTemplate to invoke different camel routes.

Regards,
Nithesh



--
View this message in context: http://camel.465427.n5.nabble.com/ProducerTemplate-creates-too-much-threads-tp5751299p5787445.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ProducerTemplate creates too much threads

Posted by Brad Johnson <br...@mediadriver.com>.
Normally you don't want to shut it down until the application is shutting
down. And then it should happen of its own accord.

Another question is why are you using the Processor interface?  Unless
there's a compelling reason just use a regular old Java bean. In a lot of
these cases you don't even need a producer template.  Just let Camel do the
work. One of the biggest mistakes I see when folks start using Camel is
they'll get some input and then write an application inside a Processor.

Camel will us reflection on your bean to figure out which method to
invoke.  It will invoked the method using the body in the Exchange so you
don't have to fool with it.  You can explicitly invoke a method on a bean
if necessary (when there are two methods that take the same datatype for
example) because in that case Camel has no way of differentiating which
method you'd like to invoke.  In a number of those cases I'll just split my
handler in two and use each in its rightful place. So if your payload is
MyPayloadBean, the a MyPayloadHandler might look like this:

public class MyPayloadHandler {

public MyPaylaodBean handle(MyPayloadBean payload)
{
   //Do something withe payload here and then just return it so Camel can
route it to the next place.
   return payload;
//In reality I don't believe you even have  to return the payload if all
you are doing is mutating data on it. It will continue being used but if
you instantiate or create a new one or a different type then you'll want to
specify the return.  I do // it anyway just to make it clear as to what is
happening there so if someone else or even I have to come back later and
change it is obvious as to what is happening.
}
 I rarely if ever use Processors and the only time I'd really think about
it is if I had to muck about with headers.  Even then I'd prefer to do it
from the Camel route if I can (and 90% of the time I can). Or if I just
need access to the information they contain and don't need to mutate it
I'll add another parameter to the method and then add @Header to tell Camel
what it is I want.

http://camel.apache.org/bean-binding.html

There's a very important point to note about all this.  Notice that your
MyPayloadHandler is not dependent on the Camel framework mechanisms. It is
decoupled and is totally portable.  It also means that you can use Plain
ol' JUnit to test the MyPayloadHandler because it is just a POJO.

In the case where you are invoking a ProducerTemplate there ins't anything
particularly wrong or bad about it but ask yourself if you couldn't just
add a .to(xxxx).  In your case, I don't know what comes before the
Processor but let's say it is a file or direct or seda or whatever.

from("direct:foo").(MyPayloadHandler.class).to("direct:invokeWS");

--You can also separately instantiate the payload handler or just
instantiate it and reference it by a name.

Notice how you are letting Camel do its job here and aren't manually having
to manipulate anything.  Are there times to use Producer or Consumer
templates?  Sure, but make sure you really need them and can't just wire in
a camel route to send it on. And really think hard if you need to a use a
Processor and can't figure out another less messy way of going about it.
If you don't have a compelling reason to use the Processor then just use
Pojo.  If you don't have a compelling reason to use the ProducerTemplate,
then just use the routes.

If you look in the Camel in Action book you'll see a section in there where
Clause talks about the difference in using bean binding versus Processor.
If I had my beat up old copy around I'd tell you what page to look on.
Unfortunately so much of the online documentation shows processors being
use that that sort of gets lost.  I assume that much of that is due to its
having been written earlier before the bean binding became robust.

If I could find my beat up old copy around here I'd tell you exactly where
to look but I'm not sure where it's at.  I've been waiting to throw money
at Claus when the new copy comes out or even review it while it is in
edit.  Santa Claus has promised sometime around Christmas or so.  I hope so
because my children have already put it on their lists.

Brad


On Sat, Sep 10, 2016 at 1:24 AM, niteshjain <ni...@gmail.com> wrote:

> Thanks for your valuable response,
>
> Now I'm using ProducerTemplate to invoke a camel route by injecting the
> template as below:
>
> public class Test implements Processor {
>     @EndpointInject(uri="direct:invokeWS")
>      ProducerTemplate producer;
>
>    @Override
>     public void process(Exchange exchange) throws Exception {
>       .....
>       .....
>        producer.requestBody(somePayload); //invokes the camel route
> "direct:invokeWS" as expected.
>       .....
>       .....
>     }
> }
>
> and It's working fine, my doubt is when do i call *producer.stop() method*
> to close down all the resources it has been using ?
>
> as my application will be running forever ! and for each SOAP request
> process() method of Test class will be invoked.
>
> Thanks,
> Nithesh
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.
> com/ProducerTemplate-creates-too-much-threads-tp5751299p5787436.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: ProducerTemplate creates too much threads

Posted by niteshjain <ni...@gmail.com>.
Thanks for your valuable response,

Now I'm using ProducerTemplate to invoke a camel route by injecting the
template as below:

public class Test implements Processor {
    @EndpointInject(uri="direct:invokeWS")
     ProducerTemplate producer;

   @Override
    public void process(Exchange exchange) throws Exception {
      .....
      .....
       producer.requestBody(somePayload); //invokes the camel route
"direct:invokeWS" as expected.
      .....
      .....
    }
}

and It's working fine, my doubt is when do i call *producer.stop() method*
to close down all the resources it has been using ?

as my application will be running forever ! and for each SOAP request
process() method of Test class will be invoked.

Thanks,
Nithesh



--
View this message in context: http://camel.465427.n5.nabble.com/ProducerTemplate-creates-too-much-threads-tp5751299p5787436.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ProducerTemplate creates too much threads

Posted by Brad Johnson <br...@mediadriver.com>.
OK, but that doesn't apply to an inject ProducerTemplate in a bean, only to
ones created on the incoming thread.

If you have something like. It is an *instance *variable. It is not created
on the incoming thread but is only created at start up time.

public class FooHandler {

@EndpointInject(uri="activemq:foo.bar")
  ProducerTemplate producer;

  public void doSomething() {
    if (whatever) {
      producer.sendBody("<hello>world!</hello>");
    }
  }

http://camel.apache.org/pojo-producing.html


Make sure you look at what they are conveying.  This not suggesting that
you create a singleton and serve up ProducerTemplates from it.  It is
saying you shouldn't create them inside the invocation (on the incoming
thread).  Specifically it says: *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.*

http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html

On Thu, Sep 8, 2016 at 10:50 PM, niteshjain <ni...@gmail.com> wrote:

> Hi,
>
> Can you please look into this query:
> http://camel.465427.n5.nabble.com/Should-i-start-stop-
> producer-templates-often-td5787400.html
>
> any help is appreciated.
>
> Thanks,
> Nithesh
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.
> com/ProducerTemplate-creates-too-much-threads-tp5751299p5787401.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: ProducerTemplate creates too much threads

Posted by niteshjain <ni...@gmail.com>.
Hi, 

Can you please look into this query:
http://camel.465427.n5.nabble.com/Should-i-start-stop-producer-templates-often-td5787400.html

any help is appreciated.

Thanks,
Nithesh



--
View this message in context: http://camel.465427.n5.nabble.com/ProducerTemplate-creates-too-much-threads-tp5751299p5787401.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: ProducerTemplate creates too much threads

Posted by Willem Jiang <wi...@gmail.com>.
These threads live with JmsProducer, and DefaultProducerTemplate has a cached pool to hold the reference of these producer, the default size of pool is 1000, which means you can see lots of threads waiting there.

You can setup the property in camel context like this to reduce the size of cached pool to force camel to shutdown the producer for you.
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
  <properties>
     <property key="CamelMaximumCachePoolSize" value="10"/>
  </properties>
...
<camelContext>

--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.iteye.com (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On May 20, 2014 at 1:10:44 AM, elena (elal5@hotmail.com) wrote:
> Hi,
>  
> Our company use ActiveMQ 5.6.0 and Camel 2.10.0. We noticed that
> ProducerTemplate creates too much threads
> TemporaryQueueReplyManager[temporary]-1 and
> JmsReplyManagerTimeoutChecker[queueName] when sending requests. The threads
> have a waiting status. This causes a problem on our production system
> deployed on Linux PC. The system has dozens of queues and dozens of clients
> sending requests to get data. Is there a way to eliminate the number of
> these threads? Why they are not stopped when producer template received the
> response?
>  
> Below is the excerpt from the stack trace:
>  
> org.apache.camel.ProducerTemplate.requestBody(java.lang.String,
> java.lang.Object)
> com.sick.service.ObjectDataService.findSortListByTunnel(java.lang.String,  
> java.lang.Integer)
> ......
>  
> As recommended, we use only one camel template:
>  
> > xmlns="http://camel.apache.org/schema/spring">
>  
>  
>  
>  
>  
> Thanks,
> Elena
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/ProducerTemplate-creates-too-much-threads-tp5751299.html  
> Sent from the Camel - Users mailing list archive at Nabble.com.
>