How to use two independent services and use the result of those service as Input of another service using ComputableFuture concept?

huangapple 未分类评论44阅读模式
英文:

How to use two independent services and use the result of those service as Input of another service using ComputableFuture concept?

问题

我正在尝试使用和理解Java 8的CompletableFuture概念。请帮我理解是否有一种方法可以按照下面的场景进行实现。

场景描述:
我有一个汽车存储库和一个用户存储库

我有个别的服务,比如:**getUserData(返回List<User>)getCarData(返回List<Car>)**来获取这些值。

现在我创建了另一个名为CarBooking存储库,它有一个名为createNewBooking的服务,该服务应该接受List<User>和List<Car>作为输入

是否有办法使用CompletableFuture创建一个链式方法,将这些服务/任务组合在一起触发。

就像CompletableFuture.supplyAsync(this::getUserData)......

我不太清楚如何加入另一个服务并将第一个和第二个值用作BiConsumer传递给第三个服务。

非常感谢您的帮助。

英文:

I am trying to use and understand Java8 CompletableFuture concept. Please help me to under if there is a way I can implement by below scenario.

Scenario Description:
I have a Car repository and a user repository.

I have individual service like: getUserData (returns List<User>) and getCarData (returns List<Car>) to fetch me the values.

Now I have created another repository called: CarBooking and it has a service called createNewBooking, which should accept List<User> and List<Car> as input.

Is there any way that I can create a chained method using CompletableFuture which can combine these services/tasks to be triggered.

Like CompletableFuture.supplyAsync(this::getUserData).....

I am not able to understand how can I join another service and use first and second value to third service as BiConsumer.

Help is much appreciated.

huangapple
  • 本文由 发表于 2020年7月25日 12:58:55
  • 转载请务必保留本文链接:https://java.coder-hub.com/63084531.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定