Reputation: 169
My requirement is to poll a database for every few minutes and get a sql. Hence my code is
<camel:route>
<camel:from uri="timer:dataRetrieve?period=5s"/>
<camel:to uri="sql:select output_obj,create_dt,destination_type from dbo.gcas_events_test where process_sw = 'N' order by create_dt desc" />
</camel:route>
I am expecting 3 fields from my data set. I want to see if the destination_type='SEC' then it has to go to a different route.
So I came up with.
<camel:route>
<camel:from uri="timer:dataRetrieve?period=5s"/>
<camel:to uri="sql:select output_obj,create_dt,destination_type from dbo.gcas_events_test where process_sw = 'N' order by create_dt desc" />
<camel:choice>
<camel:when>
<simple>${body.destination_type}='SEC'</simple>
<camel:to uri="foo" />
</camel:when>
</camel:choice>
</camel:route>
And it throws an error at the simple tag. Similar problem with ognl too. What am i doing wrong here? Also will ${body.destination_type}='SEC'
work? (assuming I have that value in the data set).
Upvotes: 0
Views: 588
Reputation: 7636
According to the Camel doc, the output of a select statement is a List<Map<String, Object>>
if not configured differently. In your case, the first destination_type
found in your result set can be accessed as follows:
${body[0][destination_type]}
The route definition should be as follows (use ==
instead of a simple =
):
<camel:route>
<camel:from uri="timer:dataRetrieve?period=5s"/>
<camel:to uri="sql:select output_obj,create_dt,destination_type from dbo.gcas_events_test where process_sw = 'N' order by create_dt desc" />
<camel:choice>
<camel:when>
<camel:simple>${body[0][destination_type]} == 'SEC'</simple>
<camel:to uri="foo" />
</camel:when>
</camel:choice>
</camel:route>
If every record of the result set should be handled one by one, then you may use a splitter:
<camel:route>
<camel:from uri="timer:dataRetrieve?period=5s"/>
<camel:to uri="sql:select output_obj,create_dt,destination_type from dbo.gcas_events_test where process_sw = 'N' order by create_dt desc" />
<camel:split>
<camel:simple>${body}</camel:simple>
<camel:choice>
<camel:when>
<camel:simple>${body[destination_type]} == 'SEC'</simple>
<camel:to uri="foo" />
</camel:when>
</camel:choice>
</camel:split>
</camel:route>
Upvotes: 1