5.5. 使用 Service Registry Maven 插件自动添加工件引用
有些 Service Registry 工件类型可能会包括从一个 工件文件到另一个工件引用。您可以通过定义可重复使用的模式或 API 工件来创建效率,然后从工件引用中的多个位置引用它们。
以下工件类型支持工件引用:
- Apache Avro
- Google Protobuf
- JSON 架构
- OpenAPI
- AsyncAPI
您可以指定单个工件并配置 Service Registry Maven 插件,以自动检测同一目录中对工件的所有引用,并自动注册这些引用。这是一个技术预览功能。
技术预览功能不被红帽产品服务级别协议(SLA)支持,且功能可能并不完善。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。
有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围。
本节展示了使用 Maven 插件注册 Avro 模式的简单示例,并自动检测并注册对简单 schema 工件引用。本例假定父 TradeKey 工件和嵌套 Exchange 模式工件在同一目录中都可用:
TradeKey 模式,带有嵌套对 Exchange schema 的引用
{
"namespace": "com.kubetrade.schema.trade",
"type": "record",
"name": "TradeKey",
"fields": [
{
"name": "exchange",
"type": "com.kubetrade.schema.common.Exchange"
},
{
"name": "key",
"type": "string"
}
]
}
Exchange 模式
{
"namespace": "com.kubetrade.schema.common",
"type": "enum",
"name": "Exchange",
"symbols" : ["GEMINI"]
}
先决条件
- 您已为您的客户端应用程序创建了一个 Maven 项目。如需了解更多详细信息,请参阅 Apache Maven 文档。
-
TradeKey模式工件和嵌套Exchange模式工件文件都位于同一目录中。
流程
更新您的 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> <phase>generate-sources</phase> <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 <clientScope>MY-CLIENT-SCOPE</clientScope> <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.avsc5 </file> <ifExists>RETURN_OR_UPDATE</ifExists> <canonicalize>true</canonicalize> <autoRefs>true</autoRefs>6 </artifact> </artifacts> </configuration> </execution> </executions> </plugin>-
构建您的 Maven 项目,例如使用
mvn package命令。