- Hands-On Reactive Programming with Reactor
- Rahul Sharma
- 231字
- 2021-08-13 15:22:56
The Flux API
Flux<T> is a general purpose reactive publisher. It represents a stream of asynchronous events with zero or more values, optionally terminated by either a completion signal or an error. It is important to note that a Flux emits the following three events:
- Value refers to the values generated by the publisher
- Completion refers to a normal termination of the stream
- Error refers to an erroneous termination of the stream:

All of the preceding events are optional. This can lead to streams of the following types:
- Infinite stream: A publisher generating only value events, and no terminal events (completion and error)
- Infinite empty stream: A stream generating no value events and no terminating events
- Finite stream: A publisher generating N finite values, followed by a terminal event
- Empty stream: A publisher generating no value events, and only terminal events
Flux supports the generation of all preceding variations, so it can be used for most of the generic use cases. It can also generate sequences of alerts for an application. The alerts are an infinite stream of values, with no terminal. Flux can also be used to stream order data from an order database. The order values get terminated at the last order value. It may be the case that there are no orders for a particular product type, making the stream empty for that type.