2

I use Spring+Camel and Java application and I can't understand how to use Loop in Camel config. Camel doc suggests:

<route>
  <from uri="direct:b"/>
  <loop>
    <header>loop</header>
    <to uri="mock:result"/>
  </loop>
</route>

How to adjust loop for my case?

<route>
    <from uri="myjms:queue:{{myqueue.name1}}"/>
    ...
    <method bean="myProcessor" method="getSomeMyObjects"> <!-- returns Collection<MyObject> -->
    <loop>
        <header>?????</header> <!-- get single MyObject?.. how???.. -->
        <to uri="myjms:queue:{{myqueue.name2}}"/>
    </loop>
</rout>

Inside bean:

<bean id="myProcessor" class="my.package.MyProcessor">

I've implemented the following methods:

getSomeMyObjects()         - returns Collection<MyObject>;
getSomeMyObject(int index) - returns single MyObject;
getSomeMyObjectsCount()    - returns the number of objects inside Collection<MyObject>;

and can implement any other methods if necessary.

Is it possible to solve this using loop in Camel config?

1 Answer 1

5

You do not need to use loop. You need to split each MyObject in different body and send them. Use splitter pattern.

<route>
    <from uri="myjms:queue:{{myqueue.name1}}"/>
    ...
    <method bean="myProcessor" method="getSomeMyObjects"> <!-- returns Collection<MyObject> -->
    <split>
        <simple>${body}</simple>
        <to uri="myjms:queue:{{myqueue.name2}}"/>
    </split>
</rout>
Sign up to request clarification or add additional context in comments.

2 Comments

It seems that this (<simple>${body}</simple>) is available in Camel 2.8.0 and later. I'm forced to work with 2.5.0 :(
Sorry - I missed namespace... Works okay for 2.5.0. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.