搜索

第 5 章 使用 Maven 插件管理 Service Registry 内容

download PDF

在开发客户端应用程序时,您可以使用 Service Registry Maven 插件来管理存储在 Service Registry 中的 schema 和 API 工件:

先决条件

  • Service Registry 已安装并在您的环境中运行。
  • 在您的环境中安装并配置 Apache Maven。

5.1. 使用 Maven 插件添加 schema 和 API 工件

Maven 插件的最常见用例是在构建客户端应用程序期间添加工件。您可以使用 注册 执行目标完成此操作。

先决条件

  • 您已为您的客户端应用程序创建了一个 Maven 项目。如需了解更多详细信息,请参阅 Apache Maven 文档

流程

  1. 更新 Maven pom.xml 文件,以使用 apicurio-registry-maven-plugin 来注册工件。以下示例显示了注册 Apache Avro 和 GraphQL 模式:

    <plugin>
      <groupId>io.apicurio</groupId>
      <artifactId>apicurio-registry-maven-plugin</artifactId>
      <version>${apicurio.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>TestGroup</groupId> 4
                        <artifactId>FullNameRecord</artifactId>
                        <file>${project.basedir}/src/main/resources/schemas/record.avsc</file>
                        <ifExists>FAIL</ifExists>
                    </artifact>
                    <artifact>
                        <groupId>TestGroup</groupId>
                        <artifactId>ExampleAPI</artifactId> 5
                        <type>GRAPHQL</type>
                        <file>${project.basedir}/src/main/resources/apis/example.graphql</file>
                        <ifExists>RETURN_OR_UPDATE</ifExists>
                        <canonicalize>true</canonicalize>
                    </artifact>
                </artifacts>
            </configuration>
        </execution>
      </executions>
     </plugin>
    1
    指定 register 作为执行目标,将 schema 工件上传到 Service Registry。
    2
    使用 ./ apis/registry/v2 端点指定 Service Registry URL。
    3
    如果需要身份验证,您可以指定身份验证服务器和客户端凭证。
    4
    指定 Service Registry 工件组 ID。如果您不想使用唯一的组 ID,您可以指定 默认组
    5
    您可以使用指定的组 ID、工件 ID 和位置注册多个工件。
  2. 构建您的 Maven 项目,例如使用 mvn package 命令。

其他资源

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.