I don't know why you have two bean's saveOne method to call.
Do you want to call foo.saveOne if the message body is the instance of Foo and call bar.saveOne if the message body is the instance of Bar?

If so you can use the Content Base Router[1] to do it, and using Simple[2] language to check the message body like this.

<camel:route>
   <camel:from uri="queue:one" />
   <camel:transacted ref="required" />
   <camel:choice>
      <camel:when>
         <camel:simple>${body} is 'FOO'</camel:simple>
         <camel:bean ref="foo" method="saveOne" />
      </camel:when>
      <camel:when>
         <camel:simple>${body} is 'BAR'</camel:simple>
         <camel:bean ref="bar" method="saveOne" />
      </camel:when>
 </camel:route>

[1]http://camel.apache.org/content-based-router.html
[2]http://camel.apache.org/simple.html

Willem
senthil.arumugam wrote:
Hi,

I am trying to consume message from an endpoint defined in my route. The
queue to which the consumer is listening, has two different nature of
messages.

For eg,

I have a queue, say "queue:one" which has messages of type Foo and Bar. When
the consumer starts listening and on message, I am getting an exception with
message like "Unable to convert body from Foo to Bar"

I am using camel-spring for all my configuration. My routing in context file
is,

<camel:route>
  <camel:from uri="queue:one" />
  <camel:transacted ref="required" />
  <camel:bean ref="foo" method="saveOne" />
  <camel:bean ref="bar" method="saveOne" />
</camel:route>

Thanks in advance.

- SK

Reply via email to