You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by pvenini <pv...@mervaros.com.ar> on 2012/01/24 19:53:21 UTC

Enrich message with data from dynamic sql query

Hi, I'm developing a info distribution system that gets an XML document with
data entries and then has to enrich it with nodes that are obtained from a
SQL database. The SQL query has to be generated using paramethers from data
inside the original XML document (they are properties of some of the nodes).
I was thinking about using the enrich statement but I don't realize how can
I generate the dynamic query (using sql: or jdbc:) without loosing the
original XML document.

Thanks

Pablo

--
View this message in context: http://camel.465427.n5.nabble.com/Enrich-message-with-data-from-dynamic-sql-query-tp5329427p5329427.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Enrich message with data from dynamic sql query

Posted by Christian Müller <ch...@gmail.com>.
Pablo,

my suggestion looks like the one below:

from("direct:start")
  .enrich("direct:enrich", myAggregationStrategie)
  .to("bean://doWhatEverYouWantWithTheEnrichedXML");

from("direct:enrich")
  .to("bean://transformMyXmlIntoAQuery")
  .to("jdbc://xxx");

Give it a try...

Best,
Christian

On Wed, Jan 25, 2012 at 3:19 PM, Pablo Venini <pv...@mervaros.com.ar>wrote:

> Christian:
>             as I see it, the problem would occur before the aggregation
> strategy; if I use a JDBC endpoint, the query would have to be placed into
>  the body of the exchange, thus replacing the original body (the XML
> document, which I have to use later to merge with the nodes I create from
> the results of the query). The same I think would happen with the SQL
> endpoint, because even if I use a SQL statement with placeholders, the
> values for those placeholders would have to came from some properties of
> the nodes, so I would need to process the XML and replace the body.
>
> Pablo
>
>  If you use the enrich EIP, you have to provide an Aggregation strategy to
>> "merge" the original exchange (which contains the xml document) and the
>> new
>> exchange (the result of your database call if you have on). Where is the
>> problem?
>>
>> Best,
>> Christian
>>
>
>
>

Re: Enrich message with data from dynamic sql query

Posted by Taariq Levack <ta...@gmail.com>.
Hi

The aggregator will take in the original exchange and then also the
exchange returned by the resource.
Give it a try.

Taariq

On Wed, Jan 25, 2012 at 4:19 PM, Pablo Venini <pv...@mervaros.com.ar>wrote:

> Christian:
>             as I see it, the problem would occur before the aggregation
> strategy; if I use a JDBC endpoint, the query would have to be placed into
>  the body of the exchange, thus replacing the original body (the XML
> document, which I have to use later to merge with the nodes I create from
> the results of the query). The same I think would happen with the SQL
> endpoint, because even if I use a SQL statement with placeholders, the
> values for those placeholders would have to came from some properties of
> the nodes, so I would need to process the XML and replace the body.
>
> Pablo
>
>
>  If you use the enrich EIP, you have to provide an Aggregation strategy to
>> "merge" the original exchange (which contains the xml document) and the
>> new
>> exchange (the result of your database call if you have on). Where is the
>> problem?
>>
>> Best,
>> Christian
>>
>
>
>

Re: Enrich message with data from dynamic sql query

Posted by Pablo Venini <pv...@mervaros.com.ar>.
Christian:
              as I see it, the problem would occur before the 
aggregation strategy; if I use a JDBC endpoint, the query would have to 
be placed into  the body of the exchange, thus replacing the original 
body (the XML document, which I have to use later to merge with the 
nodes I create from the results of the query). The same I think would 
happen with the SQL endpoint, because even if I use a SQL statement with 
placeholders, the values for those placeholders would have to came from 
some properties of the nodes, so I would need to process the XML and 
replace the body.

Pablo

>If you use the enrich EIP, you have to provide an Aggregation strategy to
>"merge" the original exchange (which contains the xml document) and the new
>exchange (the result of your database call if you have on). Where is the
>problem?
>
>Best,
>Christian



Re: Enrich message with data from dynamic sql query

Posted by Christian Müller <ch...@gmail.com>.
If you use the enrich EIP, you have to provide an Aggregation strategy to
"merge" the original exchange (which contains the xml document) and the new
exchange (the result of your database call if you have on). Where is the
problem?

Best,
Christian

On Tue, Jan 24, 2012 at 7:53 PM, pvenini <pv...@mervaros.com.ar> wrote:

> Hi, I'm developing a info distribution system that gets an XML document
> with
> data entries and then has to enrich it with nodes that are obtained from a
> SQL database. The SQL query has to be generated using paramethers from data
> inside the original XML document (they are properties of some of the
> nodes).
> I was thinking about using the enrich statement but I don't realize how can
> I generate the dynamic query (using sql: or jdbc:) without loosing the
> original XML document.
>
> Thanks
>
> Pablo
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Enrich-message-with-data-from-dynamic-sql-query-tp5329427p5329427.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Enrich message with data from dynamic sql query

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Jan 24, 2012 at 7:53 PM, pvenini <pv...@mervaros.com.ar> wrote:
> Hi, I'm developing a info distribution system that gets an XML document with
> data entries and then has to enrich it with nodes that are obtained from a
> SQL database. The SQL query has to be generated using paramethers from data
> inside the original XML document (they are properties of some of the nodes).
> I was thinking about using the enrich statement but I don't realize how can
> I generate the dynamic query (using sql: or jdbc:) without loosing the
> original XML document.
>

Often a Java bean is a good idea to access a JDBC data source. Then
you can construct the query, execute and get the result back, and
merge in a result as you want.

And from the Java bean you can use a ProducerTemplate for example if
you want to send a message to a Camel endpoint, and get back a
message.



> Thanks
>
> Pablo
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Enrich-message-with-data-from-dynamic-sql-query-tp5329427p5329427.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/