¿Cómo manejar la idempotencia en la capa de servicio?

I Have a SOA App where i want to incorporate some idempotency mechanism on the service layer. I'm using WCF for messaging.

How do you handle idempotency in your apps? do you have some sample code? my goal is to prevent the same message (eg. CreateOrder) to be processed more than once (if configured like that).

preguntado el 09 de enero de 11 a las 12:01

1 Respuestas

idempotency isn't about detecting and stopping a message being processed twice. It has more to do with a message processed 2 or more times has the same side-effects. So rather than Append/Create/Update operations I would just have a Store operation that does both insert and updates.

So in your CreateOrder example just get the client to pass a guid which your service will insert if its does not exist or updates if it does.

Respondido el 09 de enero de 11 a las 15:01

Which is fine for order creation, now what about actions such as updates which don't have a "natural" reason to retain the guid of the request? - djna

you don't need to retain the guid, just ensure the update ends up in the same state when executed multiple times, which unless you're for some reason creating rows with your updates, is the default behaviour. - Mythz

Modify order quantity? Surely updates can change the value of a row? If the service has an interface saying "increment quantity" then it's not idempotent, if it has an interface saying "set value to x" then we need to deal with some kind of optimistic locking otherwise we can't deal with successve reasonable operations. I'm arguing that not all interface design issues are addressed by guid on the request. - djna

Would it be better for the client to request an identifier Guid from the server first? That way Guid is created on central system. Down side would be two requests for each insert. - Milambardo

@Milambardo That wouldn't be necessary, the changes of Guid collisions is extremely unlikely. - Mythz

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.