Retry Operators
Learn when and how to use the Retry and RetryWhen operators.
We'll cover the following...
There are some operations that require retrying either immediately or at a later point in time if they fail to complete.
Example
Say, for example, we’re developing a chat application, and a user sends a message to another user. If sending that message fails because of a bad network connection, that message should get resent at a better point in time—for example, when the sender establishes a better network connection. While there are many ways to solve this problem, a simple solution would be to add retry logic until the operation succeeds.
public class Message {private String sender;private String receiver;private String text;public Message(String sender, String receiver, String text) {this.sender = sender;this.receiver = receiver;this.text = text;}}
public class NetworkClient {Observable<Message> sendMessage(Message message) {// Send message network call here}}
In the example above, we have a simple Message
POJO that contains some text as well as the sender and the receiver of the message. In addition, we’ve added a method in NetworkClient
to send a Message
to the receiver, which returns an Observable<Message>
that emits the sent message ...