5.3. 使用 Service Registry Maven 插件添加工件引用
服务 Registry 工件类型,如 Apache Avro、Protobuf 和 JSON Schema 可以包括从一个 工件文件到另一个工件文件中的工件引用。您可以通过定义可重复使用的模式和 API 工件来创建效率,然后从工件引用的多个位置引用它们。
本节演示了一个简单的示例,它使用 Service Registry Maven 插件将工件引用注册到 Service Registry 中的简单 Avro schema 工件。本例假定服务 Registry 中已创建了以下 Exchange schema 工件:
Exchange schema
{
"namespace": "com.kubetrade.schema.common",
"type": "enum",
"name": "Exchange",
"symbols" : ["GEMINI"]
}
然后,创建一个 TradeKey 模式工件,其中包括对嵌套 Exchange schema 工件的引用:
带有嵌套交换模式的 TradeKey 模式
{
"namespace": "com.kubetrade.schema.trade",
"type": "record",
"name": "TradeKey",
"fields": [
{
"name": "exchange",
"type": "com.kubetrade.schema.common.Exchange"
},
{
"name": "key",
"type": "string"
}
]
}
先决条件
- Service Registry 在您的环境中安装并运行
-
在 Service Registry 中已创建了
Exchangeschema 工件
流程
更新您的 Maven pom.xml 文件,以使用 apicurio-registry-maven-plugin 注册 TradeKey 模式,其中包含对 Exchange 模式的嵌套引用,如下所示:
<plugin>
<groupId>io.apicurio</groupId>
<artifactId>apicurio-registry-maven-plugin</artifactId>
<version>${apicurio-registry.version}</version>
<executions>
<execution>
<id>register-artifact</id>
<goals>
<goal>register</goal> 1
</goals>
<configuration>
<registryUrl>MY-REGISTRY-URL/apis/registry/v2</registryUrl> 2
<authServerUrl>MY-AUTH-SERVER</authServerUrl>
<clientId>MY-CLIENT-ID</clientId>
<clientSecret>MY-CLIENT-SECRET</clientSecret> 3
<artifacts>
<artifact>
<groupId>test-group</groupId> 4
<artifactId>TradeKey</artifactId>
<version>2.0</version>
<type>AVRO</type>
<file>
${project.basedir}/src/main/resources/schemas/TradeKey.avsc
</file>
<ifExists>RETURN_OR_UPDATE</ifExists>
<canonicalize>true</canonicalize>
<references>
<reference> 5
<name>com.kubetrade.schema.common.Exchange</name>
<groupId>test-group</groupId>
<artifactId>Exchange</artifactId>
<version>2.0</version>
<type>AVRO</type>
<file>
${project.basedir}/src/main/resources/schemas/Exchange.avsc
</file>
<ifExists>RETURN_OR_UPDATE</ifExists>
<canonicalize>true</canonicalize>
</reference>
</references>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>-
指定
register作为将 schema 工件上传到 registry 的执行目标。 -
使用
../apis/registry/v2端点指定 Service Registry URL。 - 如果需要身份验证,您可以指定身份验证服务器和客户端凭证。
-
指定 Service Registry 工件组 ID。如果您不想使用唯一组 ID,可以指定
default组。 - 使用其组 ID、工件 ID、版本、类型和位置指定 Service Registry 工件引用。您可以以这种方式注册多个构件引用。