0

私は自分のローカル マシンでspring-cloud-samplesを試しており、eureka と hystrix をサポートするシンプルな REST サービスを開発しました。

Feign クライアントへの参照を含む hystrix コマンド メソッド (@HystrixCommand 注釈付きメソッド) を介してサービスに接続するフロントエンド アプリケーションがあります。

クライアントを装う

@FeignClient("product-service")
public interface ProductClient {

    @RequestMapping(value = "product-service/{id}", method = RequestMethod.GET)
    Product getProduct(@PathVariable("id") int id);

}

Hystrix ラッパー

@Service
public class ProductHystrixClient {

    private final ProductClient productClient;

    @Autowired
    public ProductHystrixClient(ProductClient productClient) {
        this.productClient = productClient;
    }

    @HystrixCommand(groupKey = "product-service", commandKey = "getProduct", fallbackMethod = "getProductFallback")
    public Product getProduct(int id) {
        return productClient.getProduct(id);
    }

    public Product getProductFallback(int id) {
        return null;
    }

}

Spring MVC ProductService の 2 つのインスタンスを開始しました。最初のものは、期待どおり、指定された識別子に基づいて製品情報を提供します。一方、2 番目のものは、システムの依存関係の失敗をシミュレートするために、常に RuntimeException をスローします。

  if (1==1) throw new IllegalArgumentException("system dependency failure");

フロントエンド側では、hystrix クライアントを使用して製品情報を取得し、ProductService インスタンスが (リボンにより) ラウンド ロビン方式で呼び出されます。ProductService インスタンスの 1 つが常に例外を配信するという事実により、フロントエンドで複数の連続した呼び出しを行った後、ProductService 回路が開かれます (ProductService のインスタンスの 1 つが要求を正常に処理できる場合でも)。

ProductService の hystrix サーキット ブレークを回避するために、問題のある ProductService インスタンスのみを eureka から削除し、それらを正しく機能させ続けるにはどうすればよいですか? ProductService のヘルス インジケーター リソース "/health" の機能を変更して、システム依存関係のエラーを追加でチェックする必要があると思います。

カスタムヘルスチェックを実行できるspring-boot-starter- actuator の使用に遭遇しましたが、これは eureka からサービスインスタンスを取り出すのに役立たないようです。

4

0 に答える 0