【发布时间】:2020-11-19 05:34:33
【问题描述】:
假设我有一个带有 (CourseID, Name) 的课程名称对象列表。让我们将该列表称为“courseNameList”。
当有人向“
但是,在发送结果之前,我还需要附加每门课程的价格。价格将从另一个微服务中检索,并返回一个 Mono 对象。
因此,用户将看到带有(ID、名称、价格)的课程列表。价格来自其他服务。
控制器方法可能如下所示
@GetMapping("/courses")
public Flux<Course> gerProducts() {
courseNameList.stream.map(courseName -> {
//Make a webClient call to pricing service by sending coureName.getID as parameter and get the 'price' Mono object
//return the course object with id, name, price
})
//Collect and return Flux with contains list of courses!
}
我尝试了多种方法来返回 Flux。但是,我无法弄清楚如何。我需要将这些 cmets 替换为等效(或更好)的代码。
【问题讨论】:
标签: java spring-boot reactive-programming spring-webflux