役立つかもしれない 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();
}
このメソッドには 5 つのコマンドがあり、そのうちのいくつかは相互に依存していますが、それらのいずれかが失敗した場合、メソッドは例外で終了します。
これが役立つことを願っています。