-
-
Notifications
You must be signed in to change notification settings - Fork 9
docs: Document how to use ListenHTTP #765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
37fde67
docs: Document how to use ListenHTTP
sbernauer 9dd8614
Apply suggestions from code review
sbernauer a3e6214
Apply suggestions from code review
sbernauer 4d3df7a
Update docs/modules/nifi/pages/usage_guide/exposing-processors/http.adoc
sbernauer 7f3e615
Update docs/modules/nifi/pages/usage_guide/exposing-processors/http.adoc
sbernauer 6196eb0
Move sentence
sbernauer 2c228f2
wording
sbernauer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
99 changes: 99 additions & 0 deletions
99
docs/modules/nifi/pages/usage_guide/exposing-processors/http.adoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| = Exposing HTTP processors | ||
| :description: Expose NiFi ListenHTTP processor by creating Service and Ingress objects, allowing external tools to trigger workflows or send data. | ||
|
|
||
| You can use the `ListenHTTP` processor to start a HTTP webserver and listen for incoming connections. | ||
|
|
||
| In this case `POST` requests are being send to NiFi, which acts as a webhook to receive data here. | ||
| You should also be able to serve `GET` requests by using the `HandleHttpRequest` processor, however this is currently not demonstrated in this guide. | ||
|
|
||
| == 1. Create `ListenHTTP` processor | ||
|
|
||
| Let's start by creating a `ListenHTTP` processor: | ||
|
|
||
| 1. Set `Base Path` to an empty string | ||
| 2. Set `Listening Port` to `8042`. | ||
| 3. Set `Record Reader` to an `JsonTreeReader` and `Record Writer` to an `JsonRecordSetWriter` instance. | ||
| This guide assumes that JSON documents are being posted to the listener. For other document formats, change the record reader and writer accordingly. | ||
|
|
||
| You should end up with something similar to | ||
|
|
||
| image:listen-http-1.png[A ListenHTTP processor] | ||
|
|
||
| == 2. Expose `ListenHTTP` processor | ||
|
|
||
| Afterwards you need to expose the processor to the outside world. | ||
|
|
||
| For that to work, first create a Service object as follows. | ||
| In this guide, the NifiCluster is called `simple-nifi`. The name of the Nifi cluster must match the value of the `app.kubernetes.io/instance` as shown below. | ||
|
|
||
| [source,yaml] | ||
| ---- | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: simple-nifi-listen-http # Update according to NifiCluster name | ||
| spec: | ||
| type: ClusterIP | ||
| selector: | ||
| app.kubernetes.io/component: node | ||
| app.kubernetes.io/instance: simple-nifi # Update according to NifiCluster name | ||
| app.kubernetes.io/name: nifi | ||
| ports: | ||
| - name: http | ||
| port: 8042 | ||
| protocol: TCP | ||
| targetPort: 8042 | ||
| ---- | ||
|
|
||
| In case you don't have an ingress controller, you can set the Service type to `LoadBalancer` or `NodePort` instead and should be ready to go. | ||
| If you are using an ingress controller, an Ingress could look something like | ||
|
|
||
| [source,yaml] | ||
| ---- | ||
| apiVersion: networking.k8s.io/v1 | ||
| kind: Ingress | ||
| metadata: | ||
| name: simple-nifi-listen-http # Update according to NifiCluster name | ||
| spec: | ||
| rules: | ||
| - host: simple-nifi-listen-http.my.corp # Update to your host | ||
| http: | ||
| paths: | ||
| - pathType: Prefix | ||
| path: / | ||
| backend: | ||
| service: | ||
| name: simple-nifi-listen-http # Update to your Service name | ||
| port: | ||
| number: 8042 | ||
| ---- | ||
|
|
||
| === 3. Route | ||
|
|
||
| The next step is to handle different kind of messages coming in, based on the HTTP path. | ||
|
|
||
| First, create a `RouteOnAttribute` processor and connect it to the `success` output of the `ListenHTTP` processor as shown below. | ||
| Start the `ListenHTTP` processor. | ||
|
|
||
| image:listen-http-2.png[´RouteOnAttribute connected to ListenHTTP processor] | ||
|
|
||
| The `ListenHTTP` processor should now generate a FlowFile for every incoming HTTP request. | ||
| You can test this by calling `curl --verbose --data '{"hello":"NiFi"}' https://simple-nifi-listen-http.my.corp`, you should get a `HTTP/2 200` response. | ||
|
|
||
| TIP: If you get a `503 Service Temporarily Unavailable`, this probably means your Ingress controller was not able to | ||
| reach your `ListenHTTP` processor. Check that the processor is running and configured correctly. | ||
|
|
||
| This should result in one FlowFile being queued, as shown in the picture above and below. | ||
|
|
||
| image:listen-http-3.png[Resulting FlowFile] | ||
|
|
||
| In the `RouteOnAttribute` processor, add a field called `/webhook/foo` with the value of `${"restlistener.request.uri":equals('/webhook/foo')}`. | ||
| You can replace `/webhook/foo` with whatever URL your HTTP service should be reachable. | ||
| This guide also added `/webhook/bar` and `/webhook/baz` in a similar way. | ||
|
|
||
| The `RouteOnAttribute` processor now has one `unmatched` output as well as one for every field you defined. | ||
| You can connect a processor for every HTTP path you routed on. | ||
|
|
||
| The result should look something like below and should allow you to consume many different HTTP `POST` requests. | ||
|
|
||
| image:listen-http-4.png[Result flow] | ||
6 changes: 6 additions & 0 deletions
6
docs/modules/nifi/pages/usage_guide/exposing-processors/index.adoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| = Exposing processors | ||
|
|
||
| There are two mechanisms to expose Nifi processors to the outside world. | ||
|
|
||
| 1. xref:nifi:usage_guide/exposing-processors/http.adoc[HTTP traffic] | ||
| 2. xref:nifi:usage_guide/exposing-processors/tcp.adoc[Generic TCP traffic] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.