如何使用HystrixCommand注释进行同步调用

时间:2019-04-04 05:00:09

标签: spring spring-boot hystrix

我正在使用hystrix命令进行多个下游http调用。我需要等待主要服务的响应,然后才能开始进行其他http调用。

@Service
public class ServiceProxy {
    @HystrixCommand(fallBackMethod="...")
    public MainObject callMainService() {
    // call some remote service
    }

    @HystrixCommand(fallBackMethod="...")
    public SomeOtherObject1 callService1(MainObject mainObject) {
    }

    @HystrixCommand(fallBackMethod="...")
    public SomeOtherObject2 callService2(MainObject mainObject) {
    }
}

@RestController
public class MyController {

@Autowired
private ServiceProxy proxy;

@GetMapping
public Response someOperation() {
    MainObject mainObject = proxy.callMainService();
    SomeOtherObject1 obj1 = proxy.callService1(mainObject);
    SomeOtherObject2 obj2 = proxy.callService2(mainObject);
    ....
    return response;
}
}

对于上面的代码,我希望callService1和callService2调用能够等到callMainService返回响应为止。但是,甚至在callMainService完成之前,都会使用null参数调用callService1和callService2。

我在hystrix文档中读到,有一种方法可以进行同步调用。 https://github.com/Netflix/Hystrix/wiki/How-To-Use#Synchronous-Execution注释支持吗?

0 个答案:

没有答案