【发布时间】:2020-03-31 09:05:28
【问题描述】:
我有一个控制器,它调用一个 web 服务来启动一个批处理作业,当返回结果时,它应该根据这个结果调用另一个 REST API。然后它应该等待新的结果,并将第二个结果返回给用户:
@RestController
public class LaunchController {
@PostMapping(path = "/launch", consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<LaunchResult> launch(@Valid @RequestBody LaunchParams params) {
// in launch() I call the first REST API
LaunchResult result = myService.launch(params);
// here I need to call another REST API
AnotherResult result2 = callAnotherWebAPIBasedOnThisResult(result);
return ResponseEntity.ok(result2);
}
现在我想知道像这样(同步)并且在一个控制器中执行它是一种好习惯吗?是否存在其他方法?
【问题讨论】: