I'm creating an Camel route that consumes data from Cassandra DB using CQL component and I want to pass multiple parameters to the where statement.
How can I pass multiple parameters to construct the prepared stratement internally?
I've checked in DOC and I found the way to pass one parameter:
rest("cassandra")
.get()
.route()
.routeId("teste")
.removeHeaders("Camel*")
.setHeader(Exchange.HTTP_METHOD, simple(HttpMethod.GET.name()))
.process(e-> e.getIn().setBody("Gabriel")
.to("cql://localhost:9042/teste?cql=SELECT * FROM teste_table where name = ? ALLOW FILTERING")
The way above works fine, but I want to pass more than one parameter.
After some retries, I found a way to do it, simply passing an object array in the exchange in body, see below:
import com.datastax.driver.core.LocalDate;
import com.datastax.driver.core.Row;
...
rest("cassandra")
.get()
.route()
.routeId("test-route")
.removeHeaders("Camel*")
.setHeader(Exchange.HTTP_METHOD, simple(HttpMethod.GET.name()))
.process(e-> e.getIn().setBody(new Object[] {"Gabriel", LocalDate.fromYearMonthDay(1994, 10, 25)}))
.to("cql://localhost:9042/teste?cql=SELECT * FROM teste_table where name = ? and date_of_birth= ? ALLOW FILTERING")
.process(e -> {
Row[] rows = e.getIn().getBody(Row[].class);
for (Row row : rows)
System.out.println("name: " + row.getString("name") + ", idade: " + row.getInt("idade"));
});