Reactive Stream API
2 min readOct 14, 2024
Reactive stream is a specification created by engineers from netflix, lightbend and vmware. It contains 4 interfaces
- Reactive Streams is a specification that provides a standard for asynchronous stream processing with non-blocking back pressure.
- It defines a set of interfaces and contracts that enable interoperability between different reactive libraries and components.
- It defines a set of rules for asynchronous stream processing with non-blocking back pressure
- The Reactive Streams API allows developers to build reactive applications and stream processing pipelines in a consistent and composable manner.
- Reactive streams are introduced in java9
Reactive streams are immutable
- Publisher
- Subscriber
- Subscription
- Processor
Publisher
- A
Publisheris a provider of a potentially unbounded number of sequenced elements, publishing them according to the demand received from itsSubscriber(s) - Publisher represents the datasource eg: database, remoteservers etc. which holds the data.
- A
Publishercan serve multipleSubscribers subscribedsubscribe(Subscriber)
public interface publisher<T>{Get Webencyclop’s stories in your inbox
Join Medium for free to get updates from this writer.
public void subscribe(Subscriber s);
}
subscribe
- Request
Publisherto start streaming data. - This is a "factory method" and can be called multiple times, each time starting a new
Subscription. - Each
Subscriptionwill work for only a singleSubscriber. - A
Subscribershould only subscribe once to a singlePublisher. - If the
Publisherrejects the subscription attempt or otherwise fails it will signal the error viaSubscriber.onError(Throwable). - Parameters:
s- theSubscriberthat will consume signals from thisPublisher
Subscriber
public interace subscriber<T>{
public void onSubscribe(Subscriber s);
public void onNext(T t);
public void onError(Throwable t);
public void onComplete();
}Subscription
public interace Subscription<T>{
public void request(long n);
public void cancel();
}Processor
processor extends Subscriber and publisher
public interface Processor<T, R> extends Subscriber<T>, Publisher<R>{
}





