You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by moxximus <mc...@gmail.com> on 2013/03/20 20:20:32 UTC

When are @Consumed methods called by the JPA component?

I've ran into a bit of odd behavior from the JPA component. I've configured a
JPA consumption route as follows:

from("jpa:com.models.MyRecord?consumeDelete=false&consumer.query=select r
from com.models.MyRecord r where r.batchID = NULL").to("direct:jpaOut");

The model contains the following update function:

@Consumed
public void consume() {
    batchID = "MyNewBatch";
}

This updates the database perfectly fine, as expected. My issue comes in
when attempting to use the batchID further down the route. I thought that
the @Consumed function would be executed before the message is passed out of
the JPA component. I've tried synchronizing all functions that interact with
the batchID field but this doesn't resolve the issue. This leads me to
believe that the @Consumed function isn't guaranteed to be executed before
the message is passed out of the JPA component.

Can any confirm or deny this? I can put together a unit test from my code if
someone can confirm this is unexpected behavior.



--
View this message in context: http://camel.465427.n5.nabble.com/When-are-Consumed-methods-called-by-the-JPA-component-tp5729562.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: When are @Consumed methods called by the JPA component?

Posted by Claus Ibsen <cl...@gmail.com>.
You can just call a method on your bean as the 1st thing in the Camel route.

But yeah we can also add support for a @PreConsumed annotation.
Fell free to log a JIRA ticket.

And as always contributions is welcome
http://camel.apache.org/contributing.html


On Thu, Mar 21, 2013 at 2:28 PM, moxximus <mc...@gmail.com> wrote:
> Is there a reason it can't be called before the message is routed, even if
> its not guaranteed to finish before the message is routed?
>
> Executing @Consumed functions is part of the stated functionality of the JPA
> component. It seems logical that the work occurs while the message is still
> at such a node in the route. At the very least, if the function is started
> but not necessarily finished before sending out the message, one can use
> synchronization to force the completion of the function if so desired.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/When-are-Consumed-methods-called-by-the-JPA-component-tp5729562p5729615.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: When are @Consumed methods called by the JPA component?

Posted by moxximus <mc...@gmail.com>.
Is there a reason it can't be called before the message is routed, even if
its not guaranteed to finish before the message is routed?

Executing @Consumed functions is part of the stated functionality of the JPA
component. It seems logical that the work occurs while the message is still
at such a node in the route. At the very least, if the function is started
but not necessarily finished before sending out the message, one can use
synchronization to force the completion of the function if so desired.



--
View this message in context: http://camel.465427.n5.nabble.com/When-are-Consumed-methods-called-by-the-JPA-component-tp5729562p5729615.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: When are @Consumed methods called by the JPA component?

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Mar 20, 2013 at 8:20 PM, moxximus <mc...@gmail.com> wrote:
> I've ran into a bit of odd behavior from the JPA component. I've configured a
> JPA consumption route as follows:
>
> from("jpa:com.models.MyRecord?consumeDelete=false&consumer.query=select r
> from com.models.MyRecord r where r.batchID = NULL").to("direct:jpaOut");
>
> The model contains the following update function:
>
> @Consumed
> public void consume() {
>     batchID = "MyNewBatch";
> }
>
> This updates the database perfectly fine, as expected. My issue comes in
> when attempting to use the batchID further down the route. I thought that
> the @Consumed function would be executed before the message is passed out of
> the JPA component. I've tried synchronizing all functions that interact with
> the batchID field but this doesn't resolve the issue. This leads me to
> believe that the @Consumed function isn't guaranteed to be executed before
> the message is passed out of the JPA component.
>
> Can any confirm or deny this? I can put together a unit test from my code if
> someone can confirm this is unexpected behavior.
>

Its run AFTER the exchange is done being routed (eg at the end).
The docs on the web-site could be a bit more clear yeah.


>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/When-are-Consumed-methods-called-by-the-JPA-component-tp5729562.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen