2 Replies Latest reply on Feb 20, 2009 4:01 PM by Brett Levasseur

    Using process node vs the to node

    Brett Levasseur Newbie

      I have a question about the difference between nodes in Camel. I have some code like the following:

       

      from(a).process(b).to(c)

       

      Here my 'b' refers to a class that implements the Processor interface while 'c' refers to a regular Java class. It seems like I could rewrite my code (in b and c) so that both of these nodes were process:

       

      from(a).process(b).process(c)

       

      or I could rewrite it so that both nodes were to.

       

      from(a).to(b).to(c)

       

      Also the Defining Routes documentation (available at http://fusesource.com/docs/router/1.5/defining_routes/defining_routes.pdf) notes on page 56 that, "every node in a route, except for the initial endpoint, is a processor".

       

      So is there a real difference between using a node like process as opposed to the to node or vice versa? Do these different nodes actually give you different options on what you can do, if so what are they? Is there a real reason why you might choose to use one over the other?

       

      Brett

        • 1. Re: Using process node vs the to node
          Claus Ibsen Master

          Yes you can rewrite it.

           

          However they different options is there for a reason.

           

          1)

          Process is the interface/method that Camel uses internally in the routing engine to route message. You can view it as: consume -> process -> process -> process... as how Camel when you go far down in the routing engine.

           

          Process can also be used by end users so you can write some Java Code what should happen.

           

          This is expressed in the DSL as: .process or .processRef

           

          2)

          To is used to route to an Endpoint destination, that can be more or less anything.  For example all the Camel components such as: JMS, HTTP, File etc. etc.

           

          And even java code using the Bean, see next

           

          3)

          Bean is a very key component in Camel. In fact on the front page its highlighted as one of Camels key assets.

           

          You can route to a Bean (aka POJO) to allow Camel to invoke any arbitrary code you have. This allows you to be 100% in your code on any Camel class/interface. This is called non invasive API. So you can reuse/use any code you have. Imagine you have a .jar file with some existing code. Just route it to your Bean and maybe give Camel a hint which method to invoke

           

          This can be done using .bean, .beanRef or .to("bean:myBean"

           

           

          Choosing Process over Bean. I regard best practice to use Bean instead of Process so you can use any code you have and dont have to be dependt on any Camel .jars. The code is just plain Java code and any developers know how to do this. Also unit testing is easier as you dont have to find out how to instantiate any camel classes to pass in into your method.

          • 2. Re: Using process node vs the to node
            Brett Levasseur Newbie

            Thank you for the clarification.

             

            Brett