5.2. 自定义 API 服务注解值
默认情况下,Maven Fabric8 插件运行 Fabric8 服务发现功能增强器。增强器向 Fuse Rest DSL 项目的 API 服务添加了注解,以便 API 服务可以被 3scale 发现,如 Red Hat 3scale API 管理 管理门户指南中的使用服务发现 所述。
enricher 为一些注解使用默认值,并从项目的 camel-context.xml
文件中获取其他注解的值。
您可以通过在 Fuse 项目 pom.xml
文件中定义值或 service.yml
文件中定义的值来覆盖 camel-context.xml
文件中定义的值。(如果您在两个文件中都定义了值,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>
<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>
Copy to Clipboard Copied! 将 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>
<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>
Copy to Clipboard Copied! - 保存您的更改。
另外,您可以使用 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
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