Header Ads

What is Flux and Mono in spring boot ?

Flux and Mono are two types of reactive data types provided by the Spring Framework's Reactive Streams API, which is used in Spring Boot's WebFlux module.

A Flux is a reactive type that represents a stream of 0..N elements, which can be emitted asynchronously over time. It is used to handle a potentially large number of data elements, where each element can be processed asynchronously without blocking the thread. The data elements can be emitted by the publisher of the stream, and can be consumed by the subscriber at the subscriber's own pace.

On the other hand, Mono is a reactive type that represents a stream of 0..1 element, which can also be emitted asynchronously over time. It is used to handle a single result or value, where the result can be either present or not. It can be used to represent asynchronous operations that return either a single value or none.

In Spring Boot's WebFlux module, Flux and Mono are commonly used in combination with reactive APIs like WebClient to perform non-blocking HTTP calls, database operations, and other I/O operations. Using these reactive types can help in building scalable, non-blocking applications that can handle high levels of concurrency.

No comments

Internal Working of HashMap

A HashMap is a data structure that allows for fast retrieval of data based on ...

Powered by Blogger.