In ProjectReactor or Reactive Streams, Nothing Happens Until You subscribe().
Reactive streams data flow will not happen unless until someone subscribe to it, but I see for all REST APIs like finds, save and inserts are not calling subscribe explicitly but data is flowing between producer and subscribers.
@RestController
class PersonController {
private final PersonRepository repository;
public PersonController(PersonRepository repository) {
this.repository = repository;
}
@GetMapping("/all")
public Flux<Person> index() {
return repository.findAll();
}
@GetMapping("/people")
Flux<String> namesByLastname(@RequestParam Mono<String> lastname) {
Flux<Person> result = repository.findByLastname(lastname);
return result.map(it -> it.getFullName());
}
@PostMapping("/people")
Flux<People> AddPeople(@RequestBody Flux<Person> people) {
return repository.saveAll(people);
}
}
why do we no need to call subscribe for REST Endpoints to start a data flow in Project Reactor?
How REST endpoints (HTTP requests) are auto-subscribing to Reactive Streams for data flow when i call from browser?
am i missing something here ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…