1 Reply Latest reply on Dec 4, 2008 2:20 PM by davsclaus

    Conditional Routing?

    james.kavanagh

      Hi there,

       

      I've inherited a solution that uses Apache Camel and I'm trying to do something with it that doesn't seem possible.

       

      The following simple route defintion is fine for most purposes

      from(jmsX).bean(msgConsumer, "processMessage")

      This consumes a message from a JMS queue and feeds it to the bean of my choice. However in some circumstances the bean in not able to process messages correctly and so I don't want the route to be enabled. What I'd like to do is wrap it in a condition e.g.

      if(blah).from(jmsX).bean(msgConsumer, processMessage")

      I tried using a filter but realised that this doesn't really do what I need.

      Does anyone know how I can do this without writing a nasty hack?

       

      Cheers,

      James

        • 1. Re: Conditional Routing?
          davsclaus

          Hi

           

          1)

          What do you want to happen with the JMS message when the bean can not process it? Should it

          - commit

          - rollback (put back on queue)

           

          For rollback you need to use transacted JMS, and then it should happend automatically if your bean just throws an exception if it can not process the message.

           

          However if you want the JMS message to commit then you need to deal what should happen.

           

          2)

          How does you bean determine it can not process the message?

          - thrown an exception

          - or some other condition? like a method that returns a boolean?

           

          3)

          What should happen with the message if #2 can not process the message? Should it just be forgotten? Or routed to another JMS queue or other store?

           

           

          4)

          Are you looking for to pause/start the JMS consumer depending on some conditions? If so then it requires a bit manual Java code to start and stop consumers on-the-fly.