just() is a Project Reactor factory operation for creating a Flux or Mono from specified existing objects. Flux.just() can publish several values, while Mono.just() represents one value in a reactive pipeline. section 11.3.1 section 11.2
Creating and consuming a Flux
Flux<String> fruitFlux = Flux.just("Apple", "Orange", "Grape", "Banana", "Strawberry"); fruitFlux.subscribe(f -> System.out.println("Here's some fruit: " + f)); Creating the Flux does not start data flow. Calling subscribe() activates the publisher and sends its values to the subscriber. section 11.3.1
Use just() when:
- You already have one or more objects that should drive a reactive publisher. section 11.3.1
- You want to place a known value at the beginning of a pipeline and transform it with operations such as map(). section 11.2
- You want to verify emitted values and completion with StepVerifier rather than only printing them. section 11.3.1
@Test
public void createAFlux_just() {
Flux<String> fruitFlux = Flux
.just("Apple", "Orange", "Grape", "Banana", "Strawberry");
}
This listing shows a complete Flux.just() test setup with five specified fruit values. section 11.3.1
