camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: question: best practice to use camel's Producer class
Date Thu, 10 Dec 2009 15:33:45 GMT
On Thu, Dec 10, 2009 at 4:11 PM, Nick Chistyakov <chikolad@gmail.com> wrote:
> Hello James,
>
> Thanks for a fast response!
> My question is actually about Producer - not about Processor.
> Your answer is not less valuable though :))
>
> Hello Claus,
> Do you mean that for a case like this:
>
> public final class OrderProcessor implements Processor {
>
>    public void process(Exchange exchange) {
>        try {
>
>            Order order = exchange.getIn().getBody(Order.class);
>
>            order.doSomethingWithOrder();
>
>            Producer producer = exchange.getContext()
>                    .getEndpoint("jms:queue:orders")
>                    .createProducer();
>
>            producer.start();
>
>            Exchange statusExchange = producer.createExchange();
>            statusExchange.getIn().setBody(order);
>            producer.process(statusExchange);
>
>            producer.stop();
>
>        } catch (Exception e) {
>            e.printStackTrace();
>        }
>    }
>
>
> }
>
> it is better to have producer as a member of class OrderProcessor?
> or because of that local cache I can forget about it?
>

No its best as a member especially for producers which are "expensive
to create such as JMS stuff" as opposed to a logger producer, a file
producer etc.

The cache is when you use ProducerTemplate and not hand crafting a
Producer using the API as you do.

ProducerTemplate template = context.newProducerTemplate();
Exchange reply = template.send("jms:queue:foo", exchange);


> Best regards,
> Nick
>
> On Thu, Dec 10, 2009 at 5:58 PM, Claus Ibsen <claus.ibsen@gmail.com> wrote:
>
>> On Thu, Dec 10, 2009 at 3:44 PM, Nick Chistyakov <chikolad@gmail.com>
>> wrote:
>> > Hi guys,
>> >
>> > What is actually the best practice to use camel's Producer class?
>> > Is it expensive to create, for example, to create it every time when
>> message
>> > is processed.
>> > Or is it better to store a reference to it somewhere in a class scope?
>> >
>>
>> Also the ProducerTemplate has a local cache for Producers so its not
>> expensive to use.
>>
>> Just need to be aware of this FAQ
>>
>> http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html
>>
>>
>> > Best regards,
>> > Nick
>> >
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Author of Camel in Action: http://www.manning.com/ibsen/
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Mime
View raw message