0

抱歉,如果标题不清楚,我无法用这么短的一句话完全解释我的问题。

我刚刚开始使用 hystrix-javanica,我让它在我有一个围绕 1 个外部网络调用的断路器的地方工作。

我有另一个我想介绍的场景,但我不太确定最好的方法。

我有一个预订服务,每个客户请求在内部进行 5 次连续的外部网络调用,每个后续调用取决于前一个。例如,如果所有客户端请求在最后的第 5 次外部网络调用中都失败了,我希望能够断开电路(某处)并停止任何触及 5 个外部网络调用中的任何一个的请求,基本上关闭预订服务一段的时间。

您如何看待这个实施?

谢谢。

4

1 回答 1

0

这是 HystrixDemo 中的一个示例,可能会有所帮助。

public void executeSimulatedUserRequestForOrderConfirmationAndCreditCardPayment() throws InterruptedException, ExecutionException {
    /* fetch user object with http cookies */
    UserAccount user = new GetUserAccountCommand(new HttpCookie("mockKey", "mockValueFromHttpRequest")).execute();

    /* fetch the payment information (asynchronously) for the user so the credit card payment can proceed */
    Future<PaymentInformation> paymentInformation = new GetPaymentInformationCommand(user).queue();

    /* fetch the order we're processing for the user */
    int orderIdFromRequestArgument = 13579;
    Order previouslySavedOrder = new GetOrderCommand(orderIdFromRequestArgument).execute();

    CreditCardCommand credit = new CreditCardCommand(previouslySavedOrder, paymentInformation.get(), new BigDecimal(123.45));
    credit.execute();
}

此方法有五个命令,其中一些命令相互依赖,但如果其中任何一个命令失败,则该方法将退出并出现异常。

我希望这有帮助。

于 2016-03-28T16:39:16.390 回答