I’m using WebClient to create a call to send status updates to an endpoint as below:
public Disposable updateStatus(Status status) {
return WebClient.create("http://server:7777")
.post()
.body(status, Status.class)
.exchange()
.retryBackoff(2, Duration.ofSeconds(30))
.subscribe();
}
The endpoint I’m calling is not 100% available (might not be able to reach it because of lets say network issue). That is why I’m using retryBackoff
.
In the below scenario
time 0 Send status 1 Because of network issue it throws exception and schedules a try in 30 seconds (time 0 + 30) 2 Another status is available and need to be sent. However, the first one need to be cancelled.
My question is how can I cancel the call in time 1 and send the call in time 2 instead. In time 1, it will try to resend again because of retryBackoff.
Should I keep a reference of the returned Disposable and call dispose
on it before calling updateStatus
again? What is the proper way of cancelling calls?