5.2. API サービスアノテーション値のカスタマイズ
Maven Fabric8 プラグインは、デフォルトで Fabric8 Service Discovery Enricher を実行します。Enricher は、Red Hat 3scale API Management の 管理ポータルガイド の サービスディスカバリーの使用 で説明されているように、アノテーションを Fuse Rest DSL プロジェクトの API サービスに追加して API サービスを 3scale で検出できるようにします。
Enricher は一部のアノテーションのデフォルト値を使用し、プロジェクトの camel-context.xml ファイルから他のアノテーションの値を取得します。
デフォルト値や camel-context.xml ファイルで定義される値は、Fuse プロジェクトの pom.xml ファイルや service.yml ファイルに値を定義して上書きできます。(両方のファイルで値を定義する場合、Enricher は service.yml ファイルから値を使用します。) Fabric8 Service Discovery Enricher に指定できる要素の説明については、Fabric8 Service Discovery Enricher 要素 を参照してください。
手順
Fuse プロジェクトの pom.xml ファイルにアノテーションの値を指定するには、以下を実行します。
-
任意のエディターで Fuse プロジェクトの
pom.xmlファイルを開きます。 以下の例のように、
openshift-maven-pluginの依存関係を見つけます。<plugin> <groupId>org.jboss.redhat-fuse</groupId> <artifactId>openshift-maven-plugin</artifactId> <version>${fuse.version}</version> <executions> <execution> <goals> <goal>resource</goal> <goal>build</goal> </goals> </execution> </executions> </plugin>以下の例のように、Fabric8 Service Discovery Enricher を openshift-maven プラグインに依存関係として追加します。
<plugin> <groupId>org.jboss.redhat-fuse</groupId> <artifactId>openshift-maven-plugin</artifactId> <version>${fuse.version}</version> <executions> <execution> <goals> <goal>resource</goal> <goal>build</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>io.acme</groupId> <artifactId>myenricher</artifactId> <version>1.0</version> <configuration> <enricher> <config> <f8-service-discovery> <scheme>https</scheme> <path>/api</path> <descriptionPath>/api/openapi.json</descriptionPath> </f8-service-discovery> </config> </enricher> </configuration> </dependency> </dependencies> </plugin>- 変更を保存します。
または、src/main/fabric8/service.yml フラグメントを使用して、以下の例のようにアノテーション値を上書きできます。
kind: Service
name:
metadata:
labels:
discovery.3scale.net/discoverable : "true"
annotations:
discovery.3scale.net/discovery-version : "v1"
discovery.3scale.net/scheme : "https"
discovery.3scale.net/path : "/api"
discovery.3scale.net/port : "443"
discovery.3scale.net/description-path : "/api/openapi.json"
spec:
type: LoadBalancer