java - How to integrate Spring Retry with AsyncRestTemplate -
how can integrate spring retry external calls asyncresttemplate? if it's not possible, there framework supports it?
my use case:
public void dosomething() throws executionexception, interruptedexception { listenablefuture<responseentity<string>> future = asyncresttemplate.getforentity("http://localhost/foo", string.class); // tasks here responseentity<string> stringresponseentity = future.get(); // <-- how retry call? } how retry future.get() call? if external service returns 404, want avoid calling tasks in between again , retry external call? can't wrap future.get() retrytemplate.execute() because won't make call external service.
you have wrap entire dosomething (or @ least template operation , get) in retry template.
edit
instead of calling get() add listenablefuturecallback future; this...
final atomicreference<listenablefuture<responseentity<string>>> future = new atomicreference<>(asyncresttemplate.getforentity("http://localhost/foo", string.class)); final countdownlatch latch = new countdownlatch(1); future.addcallback(new listenablefuturecallback<string>() { int retries; @override public void onsuccess(string result) { if (nottheresultiwant) { future.set(asynctemplate.getfor (...)); future.get().addcallback(this); retries++; } else { latch.countdown(); } } @override public void onfailure(throwable ex) { latch.countdown(); } }); if (latch.await(10, timeunit.seconds) { ... future.get().get(); }
Comments
Post a Comment