0

I want to iterate through a java arraylist passed as message header to a camel route via bean so that each string item which is basically an url can be passed as uri argument inside tag in camel route.

I am passing an array list as message header to camel route through java bean as follows

ArrayList<String> list=new ArrayList<String>();//Creating arraylist  
              list.add("http://www.google.com");//Adding object in arraylist  
              list.add("http://www.stackoverflow.com");  
              list.add("http://www.tutorialspoint.com");  
              list.add("http://localhost:8080/sampleExample/query"); 
                exchange.getOut().setHeader("endpoints",list);

and, inside camel route i want to iterate through this list and retrieve each list item one by one so that i can pass these items in uri. here's my camel route:

<route id="myroute">
        <from id="sedp" uri="cxfrs:http://{{env:POC_HOST}}/{{env:POC_PATH}}"/>
        <log id="_log1" message="Received query request from consumers"/>
        <bean beanType="com.company.myapp.poc.logic.ProcessRequest"
            id="queryProcessor" method="checkRequestType"/>

          // I want to iterate through the list here as <toD uri="${header.endpoints.item}" />


    </route>

But i am not able to iterate through each item in list recieved as header.endpoints inside camel route.

Aniket Garg
  • 3
  • 1
  • 3

1 Answers1

0

This is the recipient list EIP pattern than can send messages to N+ destinations: http://camel.apache.org/recipient-list.html

The recipient list EIP is basically a toD but it can do 1..N endpoints. Where as toD can only do 1.

And it should be able to take your message header as-is, eg a List or Collection and send to each destination.

So do

<recipientList>
  <header>endpoints</header>
</recipientList>
Claus Ibsen
  • 56,060
  • 7
  • 50
  • 65
  • thanks Claus, I tried recipientList..but the problem with Recipient list is that it will send same message to all the endpoints... i want to send output received from 1st endpoint to 2nd and so on.. – Aniket Garg Nov 04 '17 at 09:23
  • Ah okay, then use routing slip EIP - eg a good idea is to learn some of the EIP patterns: http://camel.apache.org/eip – Claus Ibsen Nov 04 '17 at 09:49
  • thank you Claus.. i will once go through EIPs and will check if it works or not – Aniket Garg Nov 04 '17 at 10:45
  • Hey Claus, is there any way to iterate through list stored in header using and then passing each item retrieved in like we do in java? – Aniket Garg Nov 04 '17 at 11:00