2 Replies Latest reply on Feb 18, 2009 8:12 AM by Brett Levasseur

    Processing out bound messages

    Brett Levasseur Newbie

      I would like to know if it is possible to manipulate an outbound message in a Camel route.

       

      I currently have an example where I have a route that includes a process component to make some modifications to the message. When my message reaches the end of the route (my to statement) a response message is sent back. If I understand Camel correctly then the Exchange object that contains my message will return to each of the components it visited on the route until it reaches the beginning (my from statement). Just as I made a modification to my message when it came in I also need to make a modification to it as it goes out. The modification to the outbound message is similar to the one performed on the inbound message in my process component so I would like for the modification to be handled by the same class (a class that implements org.apache.camel.Processor).

       

      On the inbound message my class uses the method public void process(Exchange exchange) to catch and modify the message before sending it on. Is there an equivalent method that can be used to catch an outbound message? Any help would be appreciated, thanks.

       

      Brett

        • 1. Re: Processing out bound messages
          Claus Ibsen Master

          Hi

           

          If I understand you correctly you have a route in principle as:

           

          from -> process (A) -> to

           

          And in process (A) you modify the exchange so its content is how you want it to be before you send it to TO

           

          And now afterwards you want to modify it before its returned to FROM? You can do it by adding another process step (B) where you can modify the exchange

           

          from -> process (A) -> to -> process (B)

           

          So what happens now is that when the route reached the end (the last node in the path, that is process B). then Camel will return to the start of the route directly (not by going reverse in all the nodes). So it jumps from process (B) -> from directly.

          • 2. Re: Processing out bound messages
            Brett Levasseur Newbie

            Thanks for the reply. I was confused since I was told that a Camel route would work like

             

            from -> process(A) -> to    when a message came into from and then

             

            from <- process(A) <- to    when to returned a reply

             

             

            Brett