简体   繁体   English

Apache Nifi:从 Java 应用程序执行/触发 Nifi 处理器

[英]Apache Nifi : Execute / Trigger Nifi Processor From Java Application

Is it possible to call the Apache Nifi ListenHTTP processor or HandleHttpRequest from the java application ?是否可以从 java 应用程序调用 Apache Nifi ListenHTTP 处理器或 HandleHttpRequest Also How to send my custom arguments to ListenHTTP "Remote URL" property from a java application?另外如何将我的自定义 arguments 从 java 应用程序发送到 ListenHTTP“远程 URL”属性?

在此处输入图像描述

How to set properties of a Processor through Java API?如何通过 Java API 设置处理器的属性?

How to pass a parameter through an URL to a Nifi processor group ?如何通过 URL 将参数传递给Nifi 处理器组 And how can I start the processor group through that URL.以及如何通过该 URL 启动处理器组。

http://localhost:8080/api/firstname/{first_name}/lastname/{last_name}

I want to send first_name and last_name from my java application to Nifi processor ?我想将我的 java 应用程序中的 first_name 和 last_name 发送到 Nifi 处理器 how to achieve this?如何做到这一点?

There are a few different questions here.这里有几个不同的问题。

  1. How to interact with the ListenHTTP or HandleHttpRequest processors from a separate Java application?如何从单独的 Java 应用程序与ListenHTTPHandleHttpRequest处理器交互? - use any HTTP client from your Java application to send a request. - 使用 Java 应用程序中的任何 HTTP 客户端发送请求。 This can be as simple as using the URLConnection class orHttpClient , or using a library like Apache HTTP Components .这可以像使用URLConnection class 或HttpClient一样简单,或者使用像Apache HTTP Components这样的库。
  2. How to send custom arguments in an HTTP request from Java?如何在来自 Java 的 HTTP 请求中发送自定义 arguments? - The links above describe this process for each approach. - 上面的链接描述了每种方法的这个过程。 In general, in your Java code, you will have to construct the request (either by appending these values to the URL for a GET request, or forming the request body for a POST request).通常,在您的 Java 代码中,您必须构造请求(通过将这些值附加到 URL 以GET请求,或形成请求主体以获取POST请求)。
  3. How to set properties of a NiFi processor through the API?如何通过 API 设置 NiFi 处理器的属性? - You will not be able to invoke a Java method on NiFi when running from a separate Java application. - 从单独的 Java 应用程序运行时,您将无法在 NiFi 上调用 Java 方法。 You will need to use the NiFi REST API to perform these actions.您将需要使用NiFi REST API来执行这些操作。 There are many examples of using the REST API to do so.有许多使用 REST API 的示例 The NiFi UI is also a reference implementation, so you can use your browser's Developer Tools to observe and capture any action you make in the UI, as it calls the API directly. NiFi UI 也是一个参考实现,因此您可以使用浏览器的开发人员工具来观察和捕获您在 UI 中所做的任何操作,因为它直接调用 API。
  4. How to start a Processor Group via the API?如何通过 API 启动处理器组? - The link in the previous bullet shows an example of starting a processor via the API. - 上一个项目符号中的链接显示了通过 API 启动处理器的示例。 The process is very similar for a PG; PG 的过程非常相似。 just identify the PG via UUID instead.只需通过 UUID 识别 PG。
  5. How to send first name and last name in the specified URL format from Java?如何从 Java 以指定的 URL 格式发送名字和姓氏? - The code for this depends on the existing data structure and method of connecting. - 代码取决于现有的数据结构和连接方法。 I also suspect that the processor configuration being shown in your screenshot is an InvokeHTTP processor, not the ListenHTTP processor based on the available properties.我还怀疑屏幕截图中显示的处理器配置是InvokeHTTP处理器,而不是基于可用属性的ListenHTTP处理器。 If you want to send data from a regular Java application to NiFi via HTTP, you would configure your ListenHTTP processor to listen on a specific port and base path , and then make HTTP connections to that address.如果您想通过 HTTP常规 Java 应用程序中的数据发送NiFi,您可以将ListenHTTP处理器配置为侦听特定端口基本路径,然后将 Z293C9EA246FF9985DC6F62A650F7 连接到该地址So for example, using the default base path and port 8888, an external application would make a request to http://localhost:8888/contentListener with request body {"firstname": "Andy", "lastname": "LoPresto"} in order to provide that JSON.例如,使用默认的基本路径和端口 8888,外部应用程序将向http://localhost:8888/contentListener发出请求,请求正文为{"firstname": "Andy", "lastname": "LoPresto"}为了提供 JSON。 The flowfile content would then contain those values.然后流文件内容将包含这些值。 The ListenHTTP processor doesn't provide arbitrary URL parsing to extract those values from the querystring, so you would have to manually perform that logic. ListenHTTP处理器不提供任意 URL 解析来从查询字符串中提取这些值,因此您必须手动执行该逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM