camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Strachan <james.strac...@gmail.com>
Subject Re: question: best practice to use camel's Producer class
Date Thu, 10 Dec 2009 14:51:56 GMT
2009/12/10 Nick Chistyakov <chikolad@gmail.com>:
> 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?

FWIW typically you don't need to implement a Processor as you can use
the bean binding instead and just invoke regular java bean methods,
http://camel.apache.org/bean-binding.html

allowing you to use the annotations to extract the various things from
the message you want which simplifies your code and also means you can
hide the Camel APIs. We should strive to write application code
without any explicit middleware APIs where possible as its easier to
understand and test
http://camel.apache.org/hiding-middleware.html

In terms of whether you should use a singleton instance of a
bean/processor or not, if you are using spring/guice then you can
specify this in the IoC container. Camel will use Spring/Guice to get
an instance of your bean - which allows each instance to be stateful
if you like (e.g. injecting a new database connection or whatever) to
avoid concurrency issues when sharing the same bean instance - or if
you prefer it can be a singleton.

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://fusesource.com/

Mime
View raw message