I have to select some rows from table, send the result to a queue and then the same records as ‘Sent’ in the DB.
This how I am trying to do this but not sure how to pass a column value to the where clause of the update query for the each record of the select query.
<route>
<from uri="timer://kickoff?period=10000"/>
<setBody>
<constant>select top 10 * from tableName</constant>
</setBody>
<to uri="jdbc:test"/>
<multicast>
<to uri="activemq:queue:TESTQUEUE"/>
<setBody>
<constant>update tableName set status='Sent' where primaryKey= ${primaryKey}</constant>
</setBody>
<to uri="jdbc:test"/>
</multicast>
</route>
Will this route will run for all 10 records?
If it is not possible with JDBC/SQL component then how to achieve it with Hibernate component?
When you run a query using Camel JDBC, you will get back an ArrayList of HashMaps. See the camel documentation here:
http://camel.apache.org/jdbc.html
“The result is returned in the OUT body as an ArrayList>. The List object contains the list of rows and the Map objects contain each row with the String key as the column name.”
You will need to setup a spring bean to process this body. You can extract your primary key from the arraylist in the spring bean and set a header. From there you can use the splitter to process all the rows:
http://camel.apache.org/splitter.html