You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by chrajanirao <ra...@gmail.com> on 2009/03/12 01:44:59 UTC

Problem with IdempotentConsumer

Hi,

Below is from IdempotentConsumer.java of Camel 1.5:

public void process(Exchange exchange) throws Exception {
        String messageId =
ExpressionHelper.evaluateAsString(messageIdExpression, exchange);
        if (messageId == null) {
            throw new NoMessageIdException(exchange, messageIdExpression);
        }
        if (!messageIdRepository.contains(messageId)) {
            nextProcessor.process(exchange);
        } else {
            onDuplicateMessage(exchange, messageId);
        }
    }

The messageIdRepository.contains method is checking as well as adding the
messageId to repository if it doesn't exist already. I see this as a problem
because, before even processing message we are adding it to the repository,
how do we know if the process was successful or not? I mean in case of
failure to the process we would like to re-process the message when its
delivered again but since the repository already contains the messageId, how
do to determine whether to process it or not?

Wouldn't it be better to have "contains" and "addToRepository" as separate
operations and call addToRepository after nextProcessor.process. Another
option would be to mark initially as "Received" and after process as
"Processed".

Hope to get a reply/opinion from someone.
-- 
View this message in context: http://www.nabble.com/Problem-with-IdempotentConsumer-tp22467720p22467720.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Problem with IdempotentConsumer

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Mar 12, 2009 at 6:59 PM, chrajanirao <ra...@gmail.com> wrote:
>
> Thanks Claus. Do you know when is Camel 2.0 scheduled to be released?
See the other thread on the 2.0M1 release - eg the first milestone of 2.0.

We hope to be able to release 2.0 within 1-2 months, eg sooner the
better. But we still need a little time to get the API settled.
When 2.0 is out its much harder to change the API as it needs to be compatible.



> --
> View this message in context: http://www.nabble.com/Problem-with-IdempotentConsumer-tp22467720p22482175.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/

Re: Problem with IdempotentConsumer

Posted by chrajanirao <ra...@gmail.com>.
Thanks Claus. Do you know when is Camel 2.0 scheduled to be released?
-- 
View this message in context: http://www.nabble.com/Problem-with-IdempotentConsumer-tp22467720p22482175.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Problem with IdempotentConsumer

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Mar 12, 2009 at 1:44 AM, chrajanirao <ra...@gmail.com> wrote:
>
> Hi,
>
> Below is from IdempotentConsumer.java of Camel 1.5:
>
> public void process(Exchange exchange) throws Exception {
>        String messageId =
> ExpressionHelper.evaluateAsString(messageIdExpression, exchange);
>        if (messageId == null) {
>            throw new NoMessageIdException(exchange, messageIdExpression);
>        }
>        if (!messageIdRepository.contains(messageId)) {
>            nextProcessor.process(exchange);
>        } else {
>            onDuplicateMessage(exchange, messageId);
>        }
>    }
>
> The messageIdRepository.contains method is checking as well as adding the
> messageId to repository if it doesn't exist already. I see this as a problem
> because, before even processing message we are adding it to the repository,
> how do we know if the process was successful or not? I mean in case of
> failure to the process we would like to re-process the message when its
> delivered again but since the repository already contains the messageId, how
> do to determine whether to process it or not?
>
> Wouldn't it be better to have "contains" and "addToRepository" as separate
> operations and call addToRepository after nextProcessor.process. Another
> option would be to mark initially as "Received" and after process as
> "Processed".
>
> Hope to get a reply/opinion from someone.
Well spotted. In fact in Camel 2.0 we have refactored the code a bit
so there is a SPI interface IdempotentRepository
that supports add and contains operations.

And the approach you suggest wtih adding on completion is in fact how
the file component in Camel 2.0 works.
It has build in support for idempotent, to avoid consuming the same
file again, in case you have turned this feature on.

So the processor itself was an oversight that we didnt fix it also. So
I will create a ticket and fix the IdempotentConsumer in Camel 2.0.
https://issues.apache.org/activemq/browse/CAMEL-1451




> --
> View this message in context: http://www.nabble.com/Problem-with-IdempotentConsumer-tp22467720p22467720.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/