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

本章介绍了如何使用 Service Registry Maven 插件管理存储在 registry 中的模式和 API 工件:

先决条件

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

Maven 插件的最常见用例是在构建期间添加工件。使用 寄存器 执行目标可以达到此目的。

先决条件

  • Service Registry 在您的环境中安装并运行

流程

更新您的 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
            <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 工件上传到 registry 的执行目标。
  2. 使用 ../apis/registry/v2 端点指定 Service Registry URL。
  3. 如果需要身份验证,您可以指定身份验证服务器和客户端凭证。
  4. 指定 Service Registry 工件组 ID。如果您不想使用唯一组 ID,可以指定 default 组。
  5. 您可以使用指定的组 ID、工件 ID 和位置来注册多个工件。