camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Zoran Regvart <zo...@regvart.com>
Subject Re: How to Extract json key, value from MQTT payload
Date Tue, 06 Jun 2017 14:55:39 GMT
Hi,
so typically you would use message headers and named parameters in
your SQL, something like

.setBody("INSERT INTO MY_TABLE (ID, NAME) VALUES (:?id, :?name)")
.to("jdbc:myDataSource")

and your processor would need to set those `id` and `name` headers on
the incoming message.

You could also use JSONPath support to set those headers, of the top
of my head, something like:

.setHeader('id', new JsonPathExpression("$.id"))
.setHeader('name', new JsonPathExpression("$.name"))
.setBody("INSERT INTO MY_TABLE (ID, NAME) VALUES (:?id, :?name)")
.to("jdbc:myDataSource")

zoran

On Tue, Jun 6, 2017 at 2:20 PM, solomon <austin.solomon007@gmail.com> wrote:
> Hi,
>
> I have created a camel route of mqtt -> jdbc which pushes the data in json
> format into MQTT topic, now I want to extract the json key and value so that
> I can insert it into jdbc database.
>
> sample json payload : { "id": 1, "name": "Test" }
>
> My Camel route looks like this :
>
>         from("mqtt:bar?subscribeTopicName=test&host=tcp://localhost:1883")
>         .process(new MyProcessor()) // Extract json data here
>         .to("jdbc:myDataSource?resetAutoCommit=false");
>
> Can any one help me on how to get the values.
>
> Thanks
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-Extract-json-key-value-from-MQTT-payload-tp5801958.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Zoran Regvart

Mime
View raw message