Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

how to configure listenerhttp processor in NIFI

avatar
Contributor

We want to configure listenhttp processor that listen our web service. question is what are the configuration in http listener processor in nifi such that when we will make curl post request this ListenHttp processor will catch the update. basically i didn't understand what i have to put in Base path (is it i have to put nifi address i.e http://localhost:8080/contentListener or our web app service URL???) what is contentListener. And is it i have to put our web app port number in listening port? in the request command what i have to put in url part

 

curl --request POST 'http://(here i have to used the nifi url)' -H 'Authorization: Key demo-key

 

i know this is very basic question but i'm just using this don't know any thing about nifi and curl command .....thanks in advance

BNucf.png

2 ACCEPTED SOLUTIONS

avatar
Master Collaborator

Hi @renuu ,

 

You can use'HandleHttpRequest' to listen for incoming GET/POST request on specific port and respond back using 'HandleHttpResponse' processor.
Add one Http Context Map controller service and use the same in both processor to map request to response, thats it.

Take a look at the below sample configurations.

This HandleHTTPRequest listens for http requests on port 8888 & specifi path i.e /curlRequest.
'Allowed path' is optional, if you just want listen for any request then you ca remove that value.

 

HandleHTTPRequest processorHandleHTTPRequest processor

 

 

HandleHTTPResponse responds to client with 201 response code and any content which is flowfile content.

 

HandleHTTPResponse processorHandleHTTPResponse processor

 

 

 

Instead of curl command I have invoked above listener with another NiFi processor (which you can consider as client)
InvokeHttp processor with target end point as above HandleHTTPRequest host & port.
I am using host as localhost as I am invoking form Nifi (local) only.
For curl command form outside, you need to use your nifi host name instead of 'localhost'.
So that would be 'http://<hostname>':8888/curlRequest

Screenshot 2020-06-03 at 9.45.54 PM.png

 

 

All together - Screenshot 2020-06-03 at 9.49.06 PM.png

 

 

 

Please ACCEPT the solution if it helps/resolves your problem.

 

Thanks

Mahendra

View solution in original post

avatar
Master Collaborator

Hi @renuu 

 

ListenHTTP also works same way -
Find below sample configuration and how to invoke using curl.

ListenHTTP listens on a specific port (in my case 8889) and a base path ('/curlRequestListener')

Screenshot 2020-06-04 at 2.17.45 PM.png

 

 

Screenshot 2020-06-04 at 2.17.55 PM.png

 

 

Using below curl command from terminal you can post data -

curl -d 'my request data'  http://<nifihostname>:8889/curlRequestListener

 

'my request data' is the sample data which I am posting to the ListenHTTP processor and same is received in processors and queued as flowfile. 

 

Received request Flowfile content -

Screenshot 2020-06-04 at 2.18.29 PM.png

View solution in original post

6 REPLIES 6

avatar
Master Collaborator

Hi @renuu ,

 

You can use'HandleHttpRequest' to listen for incoming GET/POST request on specific port and respond back using 'HandleHttpResponse' processor.
Add one Http Context Map controller service and use the same in both processor to map request to response, thats it.

Take a look at the below sample configurations.

This HandleHTTPRequest listens for http requests on port 8888 & specifi path i.e /curlRequest.
'Allowed path' is optional, if you just want listen for any request then you ca remove that value.

 

HandleHTTPRequest processorHandleHTTPRequest processor

 

 

HandleHTTPResponse responds to client with 201 response code and any content which is flowfile content.

 

HandleHTTPResponse processorHandleHTTPResponse processor

 

 

 

Instead of curl command I have invoked above listener with another NiFi processor (which you can consider as client)
InvokeHttp processor with target end point as above HandleHTTPRequest host & port.
I am using host as localhost as I am invoking form Nifi (local) only.
For curl command form outside, you need to use your nifi host name instead of 'localhost'.
So that would be 'http://<hostname>':8888/curlRequest

Screenshot 2020-06-03 at 9.45.54 PM.png

 

 

All together - Screenshot 2020-06-03 at 9.49.06 PM.png

 

 

 

Please ACCEPT the solution if it helps/resolves your problem.

 

Thanks

Mahendra

avatar
Contributor

@hegdemahendra thanks for solution...but I really want to know listenhttp processor configuration....and your explanation method is awesome with flow and configuration. Thank alot ....

avatar
Master Collaborator

Hi @renuu 

 

ListenHTTP also works same way -
Find below sample configuration and how to invoke using curl.

ListenHTTP listens on a specific port (in my case 8889) and a base path ('/curlRequestListener')

Screenshot 2020-06-04 at 2.17.45 PM.png

 

 

Screenshot 2020-06-04 at 2.17.55 PM.png

 

 

Using below curl command from terminal you can post data -

curl -d 'my request data'  http://<nifihostname>:8889/curlRequestListener

 

'my request data' is the sample data which I am posting to the ListenHTTP processor and same is received in processors and queued as flowfile. 

 

Received request Flowfile content -

Screenshot 2020-06-04 at 2.18.29 PM.png

avatar
Contributor

awesome thanks @hegdemahendra  

avatar
Explorer

Hi @hegdemahendra 

 

I have tried listenhttp processor. But I'm getting following error.

ListenHTTP[id=70ce3e99-017d-1000-1516-26d82190ff59] Failed to process session due to Failed to initialize the server: java.net.BindException: Address already in use: bind
↳ causes: java.io.IOException: Failed to bind to 0.0.0.0/0.0.0.0:8443
↳ causes: org.apache.nifi.processor.exception.ProcessException: Failed to initialize the server

 Can you help me in fixing this 

avatar
New Contributor

Hi @krishna123

 

Please try changing the port, you won't face the same issue.