无法解析 org.apache.nifi:nifi-standard-services-api-nar - 如何在 CustomProcessor 中使用 LookupService

Cannot resolve org.apache.nifi:nifi-standard-services-api-nar - How to use LookupService inside CustomProcessor

我正在实施自定义 NiFi 处理器来解码一些文件。在解码过程中,我需要为某些数据映射查找外部 CSV 记录。请注意,此解码过程很复杂,因此它必须是自定义处理器。我知道我可以设置外部 CSVRecordLookupService 然后在我的 CustomController 中我可以定义一个 属性 描述符如下

    public static final PropertyDescriptor CLIENT_LOOKUP_SERVICE =
            new PropertyDescriptor.Builder()
                    .name("Client CSV Lookup service")
                    .identifiesControllerService(LookupService.class)
                    .required(true)
                    .build();

我的第一个问题是如何引用LookupService.class,我应该使用哪个maven Jar包。经过一些调查,我发现了这个 https://mvnrepository.com/artifact/org.apache.nifi/nifi-standard-services-api-nar/1.13.0。所以我将它添加到我的 processors pom.xml 中,如下所示

        <!-- https://mvnrepository.com/artifact/org.apache.nifi/nifi-standard-services-api-nar -->
        <dependency>
            <groupId>org.apache.nifi</groupId>
            <artifactId>nifi-standard-services-api-nar</artifactId>
            <version>1.13.0</version>
        </dependency>

现在我可以编译我的 class 并且 LookupService 对代码可见。但是我无法构建 nar 或 运行 Maven,因为它给出了 Cannot resolve org.apache.nifi:nifi-standard-services-api-nar:1.13.0 错误

在IDEA中也显示错误

如何解决这个问题并在我的自定义处理器中使用 org.apache.nifi.lookup.LookupService

我相信它可能是因为它是 nar 而不是 jar。但我的问题是如何通过解决此问题仅在编译时使用 LookupService 并在 运行 时使用提供的 NiFi classes。

UPDATE

我想就此提供更新,但问题尚未完全解决。

我在 maven repo 中找到了一个罐子,里面有 LookupService

这与 org.apache.nifi.serialization.record.Record 我可以成功编译和 运行 Maven。

根据 maven repo 依赖关系,这两个都应该在范围 provided 中声明。所以我就这么做了。

现在的问题是我无法打包nar。它不喜欢我排除了 LookupService class。即使我删除提供的范围,它也不会包含在内。

[INFO] Generating documentation for NiFi extensions in the NAR...
[INFO] Found a dependency on version 1.13.0 of NiFi API
[ERROR] Could not generate extensions' documentation
java.lang.NoClassDefFoundError: org/apache/nifi/lookup/LookupService

...
...

[ERROR] Failed to execute goal org.apache.nifi:nifi-nar-maven-plugin:1.3.1:nar (default-nar) on project nifi-decoder-processors-nar: Execution default-nar of goal org.apache.nifi:nifi-nar-maven-plugin:1.3.1:nar failed: A required class was missing while executing org.apache.nifi:nifi-nar-maven-plugin:1.3.1:nar: org/apache/nifi/lookup/LookupService
[ERROR] -----------------------------------------------------
[ERROR] realm =    extension>org.apache.nifi:nifi-nar-maven-plugin:1.3.1

那么我们如何在自定义处理器中使用这个 LookupService?

为了在运行时使用它,您必须在 nifi-decoder-processors-nar 的 pom 文件中添加以下依赖项。类型是 nar

    <dependency>
        <groupId>org.apache.nifi</groupId>
        <artifactId>nifi-standard-services-api-nar</artifactId>
        <version>1.13.0</version>
        <type>nar</type>
    </dependency>

关于编译时间,在 nifi-decoder-processors-processors 的 pom 文件中添加下面(我在 Nar 的 pom.xml 存储库中找到它,你可能认为 NAR 是依赖项的集合)

    <dependency>
        <groupId>org.apache.nifi</groupId>
        <artifactId>nifi-lookup-service-api</artifactId>
        <version>1.13.0</version>
        <scope>provided</scope>
    </dependency>

see this post