Automatic service registration with SmallRye Stork for Quarkus
previewこのガイドでは、SmallRye Stork と Consul を使用して、最小限の設定または設定なしで Quarkus アプリケーションの自動登録および登録解除を有効にする方法について説明します。
|
この技術は、previewと考えられています。 preview では、下位互換性やエコシステムでの存在は保証されていません。具体的な改善には設定や API の変更が必要になるかもしれませんが、 stable になるための計画は現在進行中です。フィードバックは メーリングリスト や GitHub の課題管理 で受け付けています。 とりうるステータスの完全なリストについては、 FAQの項目 を参照してください。 |
概要
SmallRye Stork supports service registration backends like Consul and Eureka. Traditionally, developers had to explicitly configure and manually register their service instances using code. With this feature, Quarkus applications can automatically register with a supported registry (e.g., Consul) during startup and deregister during shutdown — without writing boilerplate code.
IMPORTANT: Note that automatic registration is possible only for built-in registrars such as Consul, Eureka, and Static. If you’re using a custom registrar, registration must still be handled programmatically. See the stork.adoc[Stork API documentation] for an example of programmatic service registration.
この統合により設定の手間が最小限に抑えられ、可能な限りビルド時に処理を行うという Quarkus の哲学に従っています。
動作原理
アプリケーションが起動し、quarkus-smallrye-stork に加えて stork-service-registration-consul 依存関係が存在する場合、以下の処理が行われます。
-
Quarkus はビルド時に登録設定のチェックを実行します。
-
有効な設定が検出された (または推測できる) 場合、登録メタデータが生成されます。
-
起動時、アプリケーションは検出または設定された IP アドレスとポートを使用して自動的に登録されます。
-
シャットダウン時、サービスは自動的に登録解除されます。
The stork-quickstart directory demonstrates Stork with Consul service discovery, which can be extended with automatic registration as shown below.
ユースケースおよび設定オプション
登録システムは適切なデフォルト値を使用しますが、サービスごとにきめ細かな制御を行うことも可能です。
ケース 1: 暗黙的な設定
設定は一切不要です。
<dependency>
<groupId>io.smallrye.stork</groupId>
<artifactId>stork-service-registration-consul</artifactId>
</dependency>
Quarkus は以下を自動的に使用します。
-
アプリケーション名
-
検出された IP アドレス
-
HTTP ポート
サービスは自動的に登録および登録解除されます。
ケース 2: 最小限の明示的な設定
必要な項目のみをオーバーライドします。
quarkus.stork.my-service.service-registrar.ip-address=192.168.0.42
application.properties 内にレジストラ設定が 1 つしかない場合、 quarkus.stork.my-service.service-registrar.type は不要です。
ケース 3: 複数のサービスレジストラ
複数のサービスが設定されている場合は、 quarkus.stork.<service-name>.service-registrar.type を指定する必要があります。
quarkus.stork.red-service.service-registrar.type=consul
quarkus.stork.red-service.service-registrar.port=8083
quarkus.stork.blue-service.service-registrar.type=consul
quarkus.stork.blue-service.service-registrar.port=8084
ケース 4: 登録の無効化
自動登録はデフォルトで有効になっています。登録を無効にしたい場合は、以下の設定プロパティーを使用してサービスごとに設定できます。
quarkus.stork.red-service.service-registrar.enabled=false
ケース 5: 高度なヘルスチェック設定
Consul がサービスのヘルス状態をポーリングする方法をカスタマイズします。
quarkus.stork.my-service.service-registrar.parameters.health-check-url=/q/health/live
quarkus.stork.my-service.service-registrar.parameters.health-check-interval=10s
quarkus.stork.my-service.service-registrar.parameters.health-check-deregister-after=1m
IP 検出
デフォルトでは、Quarkus は最初に使用可能なループバック以外のネットワークインターフェースを使用して IP アドレスを特定しようとします。これに失敗した場合は localhost にフォールバックします。
Docker や Kubernetes 環境では、この検出により外部から到達不可能な内部 IP が取得される可能性があることに注意してください。そのような場合は、IP とポートを明示的に設定することをお勧めします。
概要
-
最小限またはゼロ設定でサービス登録を動作可能
-
ビルド時処理による Consul とのシームレスな統合
-
サービスごとのオーバーライドをサポート
-
シャットダウン時の自動登録解除
-
他のバックエンドをサポートするための容易な拡張性
設定リファレンス
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Configuration property |
タイプ |
デフォルト |
|---|---|---|
タイプ |
デフォルト |
|
Configures the service discovery type, e.g. "consul". ServiceDiscoveryProvider for the type has to be available Environment variable: Show more |
string |
required |
ServiceDiscovery parameters. Check the documentation of the selected service discovery type for available parameters. Environment variable: Show more |
Map<String,String> |
|
Configures load balancer type, e.g. "round-robin". A LoadBalancerProvider for the type has to be available Environment variable: Show more |
string |
|
Load Balancer parameters. Check the documentation of the selected load balancer type for available parameters Environment variable: Show more |
Map<String,String> |
|
Whether automatic registration and deregistration of service instances is enabled. Environment variable: Show more |
boolean |
|
Configures service registrar type, e.g. "consul". A ServiceRegistrarProvider for the type has to be available Environment variable: Show more |
string |
|
Service Registrar parameters. Check the documentation of the selected registrar type for available parameters Environment variable: Show more |
Map<String,String> |