December 2019
Intermediate to advanced
314 pages
6h 51m
English
It's worth mentioning that SSE subscriptions can be canceled by keeping a reference to the Subscription object so that you can cancel your subscription at any time:
publisher .subscribe(new Subscriber<String>() { volatile Subscription subscription; @Override public void onSubscribe(Subscription subscription) { this.subscription = subscription; } @Override public void onNext(String s) { // when no more event is needed subscription.cancel(); } @Override public void onError(Throwable throwable) { // handle error } @Override public void onComplete() { // handle complete }});
In the preceding code snippet, when the event is emitted, the observer's onNext method is called with the item and the onComplete method is invoked immediately ...
Read now
Unlock full access