You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Poyan G <po...@gmail.com> on 2014/05/20 22:11:45 UTC

camel sql component

Hello,

I have an route there I want to insert complete message in an row in the
database, the problem is that the insert statement want # header name or
body name, and to have body name my body need to be hashmap, my body is
just an String and I want to insert the complete string in to database.
What is the best way to to this ? I do not use Java for my route it's plain
spring camel xml configuration.

Thanks

-- 
Poyan Gerami
poyan.gerami@gmail.com

Re: camel sql component

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, May 20, 2014 at 11:34 PM, Poyan G <po...@gmail.com> wrote:
> Hello Pontus,
> How are you ? :)
> Actually that was the way I solved it, but I field that it should be an
> better solution on it,
> I don't now how much overhead it is to set the body as a header ?
> I think it should be an better way to set the body in the sql statement.
> Thanks
>

Yeah for a single parameter, or just to refer to the body as is, or to
allow using simple expressions, we could maybe look at adding support
for that to the sql component,

so eg :#body just refers to the body itself

Or allow doing :#${body} and have a simple expression available, that
gives you a bit more power.
Though support for :#body is likely the easiest at first.



>
>
>
> 2014-05-20 23:20 GMT+02:00 Pontus Ullgren <ul...@gmail.com>:
>
>> Hello Poyan,
>>
>> You could try something like this to assign a header the value of the
>> body and then use the header name.
>> ------
>> <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
>>     <route>
>>       <from uri="direct:start"/>
>>       <setHeader headerName="theId">
>>         <simple>id</simple>
>>       </setHeader>
>>       <setHeader headerName="theMessage">
>>         <simple>body</simple>
>>       </setHeader>
>>       <to uri="sql:insert into messages (id, message) VALUES (:#theId,
>> :#theMessage)?dataSource=#myDataSource"/>
>>       <to uri="mock:result" />
>>     </route>
>>   </camelContext>
>> ------
>>
>> Hope this helps
>> // Pontus
>>
>> On Tue, May 20, 2014 at 10:11 PM, Poyan G <po...@gmail.com> wrote:
>> > Hello,
>> >
>> > I have an route there I want to insert complete message in an row in the
>> > database, the problem is that the insert statement want # header name or
>> > body name, and to have body name my body need to be hashmap, my body is
>> > just an String and I want to insert the complete string in to database.
>> > What is the best way to to this ? I do not use Java for my route it's
>> plain
>> > spring camel xml configuration.
>> >
>> > Thanks
>> >
>> > --
>> > Poyan Gerami
>> > poyan.gerami@gmail.com
>>
>
>
>
> --
> Poyan Gerami
> poyan.gerami@gmail.com



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: camel sql component

Posted by Poyan G <po...@gmail.com>.
created jira https://issues.apache.org/jira/browse/CAMEL-7455
My route finish:s after the sql insert, so I guss nothing happens after
that.



2014-05-21 9:14 GMT+02:00 Pontus Ullgren <ul...@gmail.com>:

> Hi,
>
> I'm just fine.
>
> Provided that you do this only within one route and do not
> pass the message over any external protocol (such as JMS)
> with the headers there should not be much overhead since
> the header value is a reference to the same String object.
>
> So make sure to set the header just before the <to uri="sql..." />
> and then remove the headers before passing the exchange to another
> transport.
>
> But as Claus suggest please open a Jira with a improvement suggestion for
> adding support for reading the body or even support simple expressions
> in the statement.
>
> // Pontus
>
>
> On Tue, May 20, 2014 at 11:34 PM, Poyan G <po...@gmail.com> wrote:
> > Hello Pontus,
> > How are you ? :)
> > Actually that was the way I solved it, but I field that it should be an
> > better solution on it,
> > I don't now how much overhead it is to set the body as a header ?
> > I think it should be an better way to set the body in the sql statement.
> > Thanks
> >
> >
> >
> >
> > 2014-05-20 23:20 GMT+02:00 Pontus Ullgren <ul...@gmail.com>:
> >
> >> Hello Poyan,
> >>
> >> You could try something like this to assign a header the value of the
> >> body and then use the header name.
> >> ------
> >> <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
> >>     <route>
> >>       <from uri="direct:start"/>
> >>       <setHeader headerName="theId">
> >>         <simple>id</simple>
> >>       </setHeader>
> >>       <setHeader headerName="theMessage">
> >>         <simple>body</simple>
> >>       </setHeader>
> >>       <to uri="sql:insert into messages (id, message) VALUES (:#theId,
> >> :#theMessage)?dataSource=#myDataSource"/>
> >>       <to uri="mock:result" />
> >>     </route>
> >>   </camelContext>
> >> ------
> >>
> >> Hope this helps
> >> // Pontus
> >>
> >> On Tue, May 20, 2014 at 10:11 PM, Poyan G <po...@gmail.com>
> wrote:
> >> > Hello,
> >> >
> >> > I have an route there I want to insert complete message in an row in
> the
> >> > database, the problem is that the insert statement want # header name
> or
> >> > body name, and to have body name my body need to be hashmap, my body
> is
> >> > just an String and I want to insert the complete string in to
> database.
> >> > What is the best way to to this ? I do not use Java for my route it's
> >> plain
> >> > spring camel xml configuration.
> >> >
> >> > Thanks
> >> >
> >> > --
> >> > Poyan Gerami
> >> > poyan.gerami@gmail.com
> >>
> >
> >
> >
> > --
> > Poyan Gerami
> > poyan.gerami@gmail.com
>



-- 
Poyan Gerami
poyan.gerami@gmail.com

Re: camel sql component

Posted by Pontus Ullgren <ul...@gmail.com>.
Hi,

I'm just fine.

Provided that you do this only within one route and do not
pass the message over any external protocol (such as JMS)
with the headers there should not be much overhead since
the header value is a reference to the same String object.

So make sure to set the header just before the <to uri="sql..." />
and then remove the headers before passing the exchange to another transport.

But as Claus suggest please open a Jira with a improvement suggestion for
adding support for reading the body or even support simple expressions
in the statement.

// Pontus


On Tue, May 20, 2014 at 11:34 PM, Poyan G <po...@gmail.com> wrote:
> Hello Pontus,
> How are you ? :)
> Actually that was the way I solved it, but I field that it should be an
> better solution on it,
> I don't now how much overhead it is to set the body as a header ?
> I think it should be an better way to set the body in the sql statement.
> Thanks
>
>
>
>
> 2014-05-20 23:20 GMT+02:00 Pontus Ullgren <ul...@gmail.com>:
>
>> Hello Poyan,
>>
>> You could try something like this to assign a header the value of the
>> body and then use the header name.
>> ------
>> <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
>>     <route>
>>       <from uri="direct:start"/>
>>       <setHeader headerName="theId">
>>         <simple>id</simple>
>>       </setHeader>
>>       <setHeader headerName="theMessage">
>>         <simple>body</simple>
>>       </setHeader>
>>       <to uri="sql:insert into messages (id, message) VALUES (:#theId,
>> :#theMessage)?dataSource=#myDataSource"/>
>>       <to uri="mock:result" />
>>     </route>
>>   </camelContext>
>> ------
>>
>> Hope this helps
>> // Pontus
>>
>> On Tue, May 20, 2014 at 10:11 PM, Poyan G <po...@gmail.com> wrote:
>> > Hello,
>> >
>> > I have an route there I want to insert complete message in an row in the
>> > database, the problem is that the insert statement want # header name or
>> > body name, and to have body name my body need to be hashmap, my body is
>> > just an String and I want to insert the complete string in to database.
>> > What is the best way to to this ? I do not use Java for my route it's
>> plain
>> > spring camel xml configuration.
>> >
>> > Thanks
>> >
>> > --
>> > Poyan Gerami
>> > poyan.gerami@gmail.com
>>
>
>
>
> --
> Poyan Gerami
> poyan.gerami@gmail.com

Re: camel sql component

Posted by Poyan G <po...@gmail.com>.
Hello Pontus,
How are you ? :)
Actually that was the way I solved it, but I field that it should be an
better solution on it,
I don't now how much overhead it is to set the body as a header ?
I think it should be an better way to set the body in the sql statement.
Thanks




2014-05-20 23:20 GMT+02:00 Pontus Ullgren <ul...@gmail.com>:

> Hello Poyan,
>
> You could try something like this to assign a header the value of the
> body and then use the header name.
> ------
> <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
>     <route>
>       <from uri="direct:start"/>
>       <setHeader headerName="theId">
>         <simple>id</simple>
>       </setHeader>
>       <setHeader headerName="theMessage">
>         <simple>body</simple>
>       </setHeader>
>       <to uri="sql:insert into messages (id, message) VALUES (:#theId,
> :#theMessage)?dataSource=#myDataSource"/>
>       <to uri="mock:result" />
>     </route>
>   </camelContext>
> ------
>
> Hope this helps
> // Pontus
>
> On Tue, May 20, 2014 at 10:11 PM, Poyan G <po...@gmail.com> wrote:
> > Hello,
> >
> > I have an route there I want to insert complete message in an row in the
> > database, the problem is that the insert statement want # header name or
> > body name, and to have body name my body need to be hashmap, my body is
> > just an String and I want to insert the complete string in to database.
> > What is the best way to to this ? I do not use Java for my route it's
> plain
> > spring camel xml configuration.
> >
> > Thanks
> >
> > --
> > Poyan Gerami
> > poyan.gerami@gmail.com
>



-- 
Poyan Gerami
poyan.gerami@gmail.com

Re: camel sql component

Posted by Pontus Ullgren <ul...@gmail.com>.
Hello Poyan,

You could try something like this to assign a header the value of the
body and then use the header name.
------
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
    <route>
      <from uri="direct:start"/>
      <setHeader headerName="theId">
        <simple>id</simple>
      </setHeader>
      <setHeader headerName="theMessage">
        <simple>body</simple>
      </setHeader>
      <to uri="sql:insert into messages (id, message) VALUES (:#theId,
:#theMessage)?dataSource=#myDataSource"/>
      <to uri="mock:result" />
    </route>
  </camelContext>
------

Hope this helps
// Pontus

On Tue, May 20, 2014 at 10:11 PM, Poyan G <po...@gmail.com> wrote:
> Hello,
>
> I have an route there I want to insert complete message in an row in the
> database, the problem is that the insert statement want # header name or
> body name, and to have body name my body need to be hashmap, my body is
> just an String and I want to insert the complete string in to database.
> What is the best way to to this ? I do not use Java for my route it's plain
> spring camel xml configuration.
>
> Thanks
>
> --
> Poyan Gerami
> poyan.gerami@gmail.com