使用 schema-registry:download 时遇到问题

Having issues with using schema-registry:download

我正在使用从此处 https://docs.confluent.io/platform/current/schema-registry/develop/maven-plugin.html 下载的模式注册表下载 maven,但我无法将模式下载到我的本地项目中。这是我的插件内容。

<plugin>
  <groupId>io.confluent</groupId>
  <artifactId>kafka-schema-registry-maven-plugin</artifactId>
  <version>6.1.0</version>
  <configuration>
    <schemaRegistryUrls>
      <param>http://localhost:8081</param>
    </schemaRegistryUrls>
    <outputDirectory>src/main/avro</outputDirectory>
    <subjectPatterns>
      <param>MysqlTest2.oms.locations-value</param>
    </subjectPatterns>
    <subjects/>
  </configuration>
</plugin>

有人可以帮忙吗?加载 Maven 更改后,我是否应该单击“清理”和“打包”以使其工作?非常感谢!!

首先,确保您拥有插件存储库

<pluginRepositories>
    <pluginRepository> 
        <id>confluent</id> 
        <name>Confluent</name> 
        <url>https://packages.confluent.io/maven/</url> 
    </pluginRepository> 
</pluginRepositories>

然后,插件有多个目标,所以你需要指定要运行,并且在编译前绑定到Maven阶段不会有什么坏处

<plugin>
    <groupId>io.confluent</groupId>
    <artifactId>kafka-schema-registry-maven-plugin</artifactId>
    <version>${confluent.version}</version>
    <executions>
        <execution>
            <id>avro-resources</id>
            <phase>process-resources</phase>
            <goals>
                <goal>download</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        ...
    </configuration>

您应该会在 Maven 构建中看到如下所示的输出

[INFO] --- kafka-schema-registry-maven-plugin:6.1.0:download (avro-resources) @ project ---
[INFO] Getting all subjects on schema registry...
[INFO] Schema Registry has XXX subject(s).
[INFO] Downloading latest metadata for mySubject-value.
[INFO] Writing schema for Subject(mySubject-value) to /project/src/main/avro/mySubject-value.avsc.

如果您需要获取特定版本,请参阅 Maven: downloading files from url 并使用 /subjects/:name/versions/:number/schema 端点