An Introduction to Reactive Streams

The original initiative

  • During the initial subscription
  • And each time a new message is received (received does not necessarily mean processed)
Publisher/subscriber interactions

The Reactive Streams API

Subscription

  • cancel(): Used by a subscriber to cancel its subscription
  • request(long): Used by a subscriber to request n messages to a Publisher

Publisher

Subscriber

  • onComplete(): Notify the subscriber when a publisher is closed
  • onError(Throwable): Notify the subscriber when a publisher is closed with an error state
  • onNext(T): Notify the subscriber a message was sent. If everything goes right, after having processed a message, the subscriber will usually invoke then Subscription.request(long).
  • onSubscribe(Subscription): Notify the subscriber that a publisher just started a subscription (through the Publisher.subscribe(Subscriber) method). This is also a way for the subscriber to keep a reference on the Subscription object provided.

Processor

API summary

onSubscribe onNext* (onError | onComplete)?

Reactive Streams IO

When to use Reactive Streams?

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Teiva Harsanyi

Teiva Harsanyi

Software Engineer @Docker 🐳 | 📖 100 Go Mistakes author | 改善