简体   繁体   中英

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 ? Also How to send my custom arguments to ListenHTTP "Remote URL" property from a java application?

在此处输入图像描述

How to set properties of a Processor through Java API?

How to pass a parameter through an URL to a Nifi processor group ? And how can I start the processor group through that 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 ? 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? - use any HTTP client from your Java application to send a request. This can be as simple as using the URLConnection class orHttpClient , or using a library like Apache HTTP Components .
  2. How to send custom arguments in an HTTP request from Java? - 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).
  3. How to set properties of a NiFi processor through the API? - You will not be able to invoke a Java method on NiFi when running from a separate Java application. You will need to use the NiFi REST API to perform these actions. There are many examples of using the REST API to do so. 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.
  4. How to start a Processor Group via the API? - The link in the previous bullet shows an example of starting a processor via the API. The process is very similar for a PG; just identify the PG via UUID instead.
  5. How to send first name and last name in the specified URL format from Java? - 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. 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.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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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