If you look to the following class of the JPA component which is a
idempotentConsumer + Repository you can fetch data from a table to see if
they have already been processed, add to the repository the new one and is
Tx aware

http://svn.apache.org/repos/asf/camel/trunk/components/camel-jpa/src/main/java/org/apache/camel/processor/idempotent/jpa/JpaMessageIdRepository.java

http://camel.apache.org/jpa.html

On Thu, Aug 30, 2012 at 3:03 PM, lorenzo <laurent.deco...@sungard.com>wrote:

> Hi Charles,
>
> I did not know about this idempotentConsumer, thanks for that.
>
> I wonder if it pays off in my case though, as I have to query the
> repository
> table so I can select things to send out based on what has already been
> sent.
>
> I have done that for now, which I think suffice for my needs:
>
>         @Override
>         protected int poll() throws Exception {
>                 final int numberOfMessagesPolled = 1;
>                 final Exchange exchange = endpoint.createExchange();
>                 final MapObject mapObject =
> mapRepository.pollNextObject(exchange
>                                 .getIn());
>                 try {
>                         getProcessor().process(exchange);
>                         mapRepository.logMessageProcessed(mapObject);
>                         return numberOfMessagesPolled;
>                 } finally {
>                         if (exchange.getException() != null) {
>                                 getExceptionHandler().handleException(
>                                                 "Error processing
> exchange", exchange,
>                                                 exchange.getException());
>                         }
>                 }
>         }
>
> if getProcessor().process(exchange); fails, then I won't log the message as
> being sent. On the other hand if the message is processed, then it is safe
> to store the value.
>
> Chances that the exchange fails after that are small, but existing, so
> probably I have to upgrade my solution to the idempotentConsumer, solely
> for
> having this transactional behaviour...
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Transaction-design-for-a-custom-compononent-tp5718361p5718392.html
> Sent from the Camel Development mailing list archive at Nabble.com.
>



-- 
Charles Moulliard
Apache Committer / Sr. Pr. Consultant at FuseSource.com
Twitter : @cmoulliard
Blog : http://cmoulliard.blogspot.com

Reply via email to