commercetools / commercetools-sdk-java-v2

The e-commerce SDK from commercetools for Java.
https://commercetools.github.io/commercetools-sdk-java-v2/javadoc/index.html
Apache License 2.0
34 stars 15 forks source link

Add retry on conflict logic #46

Closed acbeni closed 2 years ago

acbeni commented 4 years ago

We should evaluate whether how we can add a retry logic to our SDK, it would be a good exercise to see if our middleware chaining would allow such a use case.

milindsingh commented 2 years ago

It really bad to see that this has been here since ages!

jenschude commented 2 years ago

I started to take a look at it, but the middleware approach here doesn't help as the middleware only knows about the HTTP abstraction request. Therefor it's not straight forward to update the request with the new version.

A possible solution could be to extend the Request/ApiMethod classes that one can add a lambda for conflict resolution. Especially it makes more sense to decide retry per request instead of doing it globally at the client level.

jenschude commented 2 years ago

With 8.0.0 a RetryHandler has been added. It allows to wrap request and in case of a ConcurrentModificationException to retry with the updated version number

Please see https://github.com/commercetools/commercetools-sdk-java-v2/blob/e374e159b25d66e1b1b1aef3f7d2ba4ec6227aa2/commercetools/commercetools-sdk-java-api/src/integrationTest/java/commercetools/ConcurrentModificationTest.java#L31-L41