I am moving code from imperative to reactive java.
In imperative programming we hold important information in DTO/Context and pass along with request, is there a way to achieve same in reactor paradigm using spring-webflux / project-reactor ?
In other words:: how can I maintain required values from more than sequence of non blocking calls.
For instance, Let's say I have Employee and Department mongo collection and used reactive mongo repository to fetch result from database.
Employee :
empId
status: ACTIVE | INACTIVE
empName
empAge
managerId
deptIds
Department:
deptId
deptName
Sequence of calls
Flux<Employee> empFlux = empRepository.findEmployees("ACTIVE"); // (1)
Flux<Department> deptFlux= deptRepository.findDepartments(deptIds); // (2)
webclient (empId, managerId, deptId, deptName); // (3)
I googled it's seems I can use flatmap to sequnce these flows, but with each transition i will lost information in previous call.
Like in above code:
(1) : get list of ACTIVE employees
(2) : with flatmap by id we get list of eligible departments but lost information about employees.
(3) I need to make reactive rest call to webclient with information about employee , dept.
My question is how can I retain this information across sequence of non-blocking flux and Monos.