How to convert a Camel body to one of its properties

285 views Asked by At

I try to set up a simple Camel route, using Spring Boot. It reads a single column from a database table and puts a message on a ActiveMQ Artemis queue for every row.

Quite simple, but I struggle to get the column value out of the exchange body. When I log the result I see that every body in the resultset is of type LinkedCaseInsensitiveMap. Not quite what I'd expect if I read the camel-sql doc; for select that returns a single column, it should be the column type (int in my case).

What's more is that I fail to see how I can get that single value out of the exchange body and convert it to another body before storing it in ActiveMQ Artemis queue.

My route looks like this:

from("direct:test-input")
    .log(LoggingLevel.INFO, log,"Received message on test-input")
    .to("log:out")
    .to("sql: select id from vac_openingen")
    .split(body())
//            .to("jms:queue:test-messages")
    .to("log:out")

and the resulting output for each log is Exchange[ExchangePattern: InOnly, BodyType: org.springframework.util.LinkedCaseInsensitiveMap, Body: {id=13}]

How can I create a new exchange whose body is only the integer value?

1

There are 1 answers

3
TacheDeChoco On

The result on the SQL query is a list of map of key-values pairs corresponding to <col-name, col-value> entries.

So after the split, you still need to access the "id" entry.

to("sql: select id from vac_openingen")
.split(body())
    .setBody( simple("${body[id]}") )
    .to("log:out")
.end();