You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Bozo Juretic <bj...@inet.hr> on 2009/01/03 10:51:04 UTC

Best practices

Hello all,

what is the best practice of accessing the database to get dynamic 
routing info, from the RouteBuilder class in openesb environment through 
Camel SE.

I'm not really sure how and when and how many times is RouteBuilder 
class initialized so I would kindly ask you for a best practice. I use 
JPA in other EJBs in the system, but since RouteBuilder is not an EJB 
I'm not sure what is the best way to do it.

The same question for Processor() instances, if I need some database 
info for the processing in the same aforementioned environment, what is 
the best practice here as well.

Thank you and best regards,

Bozo Juretic


Re: Best practices

Posted by Claus Ibsen <cl...@gmail.com>.
On Sat, Jan 3, 2009 at 10:51 AM, Bozo Juretic <bj...@inet.hr> wrote:
> Hello all,
>
> what is the best practice of accessing the database to get dynamic routing
> info, from the RouteBuilder class in openesb environment through Camel SE.
Sounds like you talke about the dynamic router
http://activemq.apache.org/camel/dynamic-router.html

I dont think there is one best practice to access a DB. Use what means
you can or normally use. I like to use spring jdbc templates (or
ibatis in the past) as they are nice and easy and I can write the SQL
query to execute. Others jump on hibernate or JPA.

>
> I'm not really sure how and when and how many times is RouteBuilder class
> initialized so I would kindly ask you for a best practice. I use JPA in
> other EJBs in the system, but since RouteBuilder is not an EJB I'm not sure
> what is the best way to do it.
I don't know the internals of Camel SE in OpenESB. But the route
builder should only be initialized once, when it's started.
As Camel is very lightweight and usually embedded in other containers
it's that container's responsibility to handle CamelContext (that will
use the routerbuilder to build the routes) lifecycle.

> The same question for Processor() instances, if I need some database info
> for the processing in the same aforementioned environment, what is the best
> practice here as well.
If the container supports IoC it could inject the database DataSource
or what ever resource you use to access the DB. (You can also use
camel-sql, camel-jdbc etc.)
Then it could handle the lifecycle of the processor instance and you
can refer to it from the route builder

>
> Thank you and best regards,
>
> Bozo Juretic
>
>



-- 

/Claus Ibsen
Apache Camel Committer
Blog: http://davsclaus.blogspot.com/

Re: Best practices

Posted by James Strachan <ja...@gmail.com>.
2009/1/3 Bozo Juretic <bj...@inet.hr>:
> Hello all,
>
> what is the best practice of accessing the database to get dynamic routing
> info, from the RouteBuilder class in openesb environment through Camel SE.

I just wondered if you could give specifics for how you'd use the
database to get dynamic routing info?  Is it you'd like to do some
custom processing in a bean taking some contents or headers of a
message and use it to find some value in some table and use that
result to decide what endpoint to send it on to?

If so you can do that in a single method...
http://activemq.apache.org/camel/recipientlist-annotation.html

public class RouterBean {

    @Consume(uri = "activemq:someQueue")
    @RecipientList
    public String[] route(@Header("cheese") String cheese, String body) {
        // do some database query or something or other

        // lets return some endpoint(s) to route to...
        return new String[]{"activemq:bar", "activemq:whatnot"};
    }
}

Or is it more a case you want to store entire route definitions inside
the database? You could store blobs of XML in the database if you
want?


> I'm not really sure how and when and how many times is RouteBuilder class
> initialized so I would kindly ask you for a best practice. I use JPA in
> other EJBs in the system, but since RouteBuilder is not an EJB I'm not sure
> what is the best way to do it.
>
> The same question for Processor() instances, if I need some database info
> for the processing in the same aforementioned environment, what is the best
> practice here as well.

As Claus said, use whatever API or framework you prefer - be it direct
hibernate, JPA, iBatis, raw JDBC or Spring JDBC templates etc. Just
write Java code as a bean and then invoke it from your route. For more
info see

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

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

Open Source Integration
http://fusesource.com/