1
votes

I am working with Talend ESB which uses camel. My requirement is I need to do batch insert into a table, and have to create the query dynamically for different types of input.

If I create a context say extVar and default it to "insert into table_foo (foo, bar) values (:#foo, :#bar)" and then use cMessagingEndpoint component with following code "sql"+context.extVar+"?batch=true&dataSource=mysql" it works fine.

In Talend, I am able to access context.extVar inside cProcessor so I tried to load the query dynamically from there, but I couldn't.

Since I am using named parameters, I assume that I can neither use the body for query nor can I get the property/header value inside the sql statement of cMessageEndPoint.

Is there way where I can populate the query dynamically into sql statement of cMessageEndPoint.

1

1 Answers

5
votes

I was able to solve my issue. Thanks to this answer. My objective was to have a dynamic batch insert query, with cRecipientList, I was able to achieve it. I was also able to get the context variables read and be used inside the Expression of cRecipientList while loading that dynamically from cProcessor.

enter image description here

Update: I just found that you can also use .toD (available from camel version 2.16) to use simple expression language inside query. For example: you could write,

.toD("sql:${property.query}?dataSource=ds_dwh_d&batch=true")