- Профиль клиента – полученный от стороннего API
- Учетные записи клиентов – получены из другого стороннего API.
- Список преимуществ клиентов – получены из базы данных.
Код: Выделить всё
{
"profile": {
"id": "123",
"name": "John Doe",
"email": "john.doe@example.com"
},
"accounts": {
"accountNumber": "ACC-456",
"balance": 1000.0
},
"beneficiaries": [
{
"name": "John Doe Sister",
"address": "XYX"
}
]
}
Пробовал приведенный ниже код, но требование не выполняется.
Код: Выделить всё
public Flux getCustomerDashboard(String customerId) {
// Create a Mono for profile and beneficiaries
Mono profileMono = Mono.just(createDummyProfile());
Mono beneficiariesMono = Mono.just(createBene());
// Create a Flux to emit the initial data
return Mono.zip(profileMono, beneficiariesMono)
.flatMapMany(tuple -> {
// Create the dashboardDTO and set profile and beneficiaries
CustomerDashboardDTO dashboardDTO = new CustomerDashboardDTO();
dashboardDTO.setProfile(tuple.getT1());
dashboardDTO.setBeneficiaries(tuple.getT2());
// Emit the initial DTO immediately
Flux initialEmission = Flux.just(dashboardDTO);
// After a delay, fetch accounts and update the DTO
Mono updatedEmission = Mono.delay(Duration.ofSeconds(10))
.flatMap(delay -> {
CustomerAccount account = createDummyAccounts(); // Fetch accounts
dashboardDTO.setAccounts(account); // Update DTO with accounts
return Mono.just(dashboardDTO); // Emit the updated DTO
});
// Combine initial and updated emissions
return initialEmission.concatWith(updatedEmission);
})
.doOnNext(dto -> System.out.println("Emitting DTO: " + dto)); // Log emission
}
Код: Выделить всё
{
"profile": {
"id": "123",
"name": "John Doe",
"email": "john.doe@example.com"
},
"accounts": null,
"beneficiaries": [
{
"name": "John Doe sister",
"address": "xyx"
}
]
}
{
"profile": {
"id": "123",
"name": "John Doe",
"email": "john.doe@example.com"
},
"accounts": {
"accountNumber": "ACC-456",
"balance": 1000.0
},
"beneficiaries": [
{
"name": "John Doe Sister",
"address": "XYX"
}
]
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... ng-webflux
Мобильная версия