Skip to content

Commit dd338e6

Browse files
sbernauerNickLarsenNZrazvan
authored
docs: Document how to use ListenHTTP (#765)
* docs: Document how to use ListenHTTP * Apply suggestions from code review Co-authored-by: Nick <[email protected]> Co-authored-by: Razvan-Daniel Mihai <[email protected]> * Apply suggestions from code review Co-authored-by: Razvan-Daniel Mihai <[email protected]> * Update docs/modules/nifi/pages/usage_guide/exposing-processors/http.adoc Co-authored-by: Nick <[email protected]> * Update docs/modules/nifi/pages/usage_guide/exposing-processors/http.adoc Co-authored-by: Razvan-Daniel Mihai <[email protected]> * Move sentence * wording --------- Co-authored-by: Nick <[email protected]> Co-authored-by: Razvan-Daniel Mihai <[email protected]>
1 parent 1669dad commit dd338e6

File tree

8 files changed

+115
-4
lines changed

8 files changed

+115
-4
lines changed
106 KB
Loading
55.5 KB
Loading
47.1 KB
Loading
200 KB
Loading
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
= Exposing HTTP processors
2+
:description: Expose NiFi ListenHTTP processor by creating Service and Ingress objects, allowing external tools to trigger workflows or send data.
3+
4+
You can use the `ListenHTTP` processor to start a HTTP webserver and listen for incoming connections.
5+
6+
In this case `POST` requests are being send to NiFi, which acts as a webhook to receive data here.
7+
You should also be able to serve `GET` requests by using the `HandleHttpRequest` processor, however this is currently not demonstrated in this guide.
8+
9+
== 1. Create `ListenHTTP` processor
10+
11+
Let's start by creating a `ListenHTTP` processor:
12+
13+
1. Set `Base Path` to an empty string
14+
2. Set `Listening Port` to `8042`.
15+
3. Set `Record Reader` to an `JsonTreeReader` and `Record Writer` to an `JsonRecordSetWriter` instance.
16+
This guide assumes that JSON documents are being posted to the listener. For other document formats, change the record reader and writer accordingly.
17+
18+
You should end up with something similar to
19+
20+
image:listen-http-1.png[A ListenHTTP processor]
21+
22+
== 2. Expose `ListenHTTP` processor
23+
24+
Afterwards you need to expose the processor to the outside world.
25+
26+
For that to work, first create a Service object as follows.
27+
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.
28+
29+
[source,yaml]
30+
----
31+
apiVersion: v1
32+
kind: Service
33+
metadata:
34+
name: simple-nifi-listen-http # Update according to NifiCluster name
35+
spec:
36+
type: ClusterIP
37+
selector:
38+
app.kubernetes.io/component: node
39+
app.kubernetes.io/instance: simple-nifi # Update according to NifiCluster name
40+
app.kubernetes.io/name: nifi
41+
ports:
42+
- name: http
43+
port: 8042
44+
protocol: TCP
45+
targetPort: 8042
46+
----
47+
48+
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.
49+
If you are using an ingress controller, an Ingress could look something like
50+
51+
[source,yaml]
52+
----
53+
apiVersion: networking.k8s.io/v1
54+
kind: Ingress
55+
metadata:
56+
name: simple-nifi-listen-http # Update according to NifiCluster name
57+
spec:
58+
rules:
59+
- host: simple-nifi-listen-http.my.corp # Update to your host
60+
http:
61+
paths:
62+
- pathType: Prefix
63+
path: /
64+
backend:
65+
service:
66+
name: simple-nifi-listen-http # Update to your Service name
67+
port:
68+
number: 8042
69+
----
70+
71+
=== 3. Route
72+
73+
The next step is to handle different kind of messages coming in, based on the HTTP path.
74+
75+
First, create a `RouteOnAttribute` processor and connect it to the `success` output of the `ListenHTTP` processor as shown below.
76+
Start the `ListenHTTP` processor.
77+
78+
image:listen-http-2.png[´RouteOnAttribute connected to ListenHTTP processor]
79+
80+
The `ListenHTTP` processor should now generate a FlowFile for every incoming HTTP request.
81+
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.
82+
83+
TIP: If you get a `503 Service Temporarily Unavailable`, this probably means your Ingress controller was not able to
84+
reach your `ListenHTTP` processor. Check that the processor is running and configured correctly.
85+
86+
This should result in one FlowFile being queued, as shown in the picture above and below.
87+
88+
image:listen-http-3.png[Resulting FlowFile]
89+
90+
In the `RouteOnAttribute` processor, add a field called `/webhook/foo` with the value of `${"restlistener.request.uri":equals('/webhook/foo')}`.
91+
You can replace `/webhook/foo` with whatever URL your HTTP service should be reachable.
92+
This guide also added `/webhook/bar` and `/webhook/baz` in a similar way.
93+
94+
The `RouteOnAttribute` processor now has one `unmatched` output as well as one for every field you defined.
95+
You can connect a processor for every HTTP path you routed on.
96+
97+
The result should look something like below and should allow you to consume many different HTTP `POST` requests.
98+
99+
image:listen-http-4.png[Result flow]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
= Exposing processors
2+
3+
There are two mechanisms to expose Nifi processors to the outside world.
4+
5+
1. xref:nifi:usage_guide/exposing-processors/http.adoc[HTTP traffic]
6+
2. xref:nifi:usage_guide/exposing-processors/tcp.adoc[Generic TCP traffic]

docs/modules/nifi/pages/usage_guide/external_ports.adoc renamed to docs/modules/nifi/pages/usage_guide/exposing-processors/tcp.adoc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
= Exposing NiFi processor ports
2-
:description: Expose NiFi processor ports by creating Service or Ingress objects, allowing external tools to trigger workflows or send data via Kubernetes.
1+
= Exposing TCP ports
2+
:description: Expose NiFi processor ports by creating Service objects, allowing external tools to trigger workflows or send data.
33

44
Some NiFi processors allow external tools to connect to them to trigger workflows or send data.
5-
For this to work from outside the Kubernetes cluster NiFi has been deployed to, it is necessary to create Service or Ingress objects to configure Kubernetes routes for these ports.
5+
For this to work from outside the Kubernetes cluster NiFi has been deployed to, it is necessary to create Service objects to configure Kubernetes routes for these ports.
66

77
Stackable doesn't place any restriction on the type of service that can be used here.
88

@@ -28,6 +28,8 @@ spec:
2828
type: LoadBalancer
2929
externalTrafficPolicy: Cluster
3030
selector:
31+
app.kubernetes.io/name: nifi
32+
app.kubernetes.io/component: node
3133
app.kubernetes.io/instance: simple-nifi
3234
ports:
3335
- name: tcp-port
@@ -51,6 +53,8 @@ metadata:
5153
spec:
5254
type: NodePort
5355
selector:
56+
app.kubernetes.io/name: nifi
57+
app.kubernetes.io/component: node
5458
app.kubernetes.io/instance: simple-nifi
5559
ports:
5660
- port: 8123

docs/modules/nifi/partials/nav.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
** xref:nifi:usage_guide/listenerclass.adoc[]
66
** xref:nifi:usage_guide/zookeeper-connection.adoc[]
77
** xref:nifi:usage_guide/extra-volumes.adoc[]
8-
** xref:nifi:usage_guide/external_ports.adoc[]
98
** xref:nifi:usage_guide/security.adoc[]
109
** xref:nifi:usage_guide/resource-configuration.adoc[]
1110
** xref:nifi:usage_guide/log-aggregation.adoc[]
@@ -14,6 +13,9 @@
1413
** xref:nifi:usage_guide/overrides.adoc[]
1514
** xref:nifi:usage_guide/writing-to-iceberg-tables.adoc[]
1615
** xref:nifi:usage_guide/flow-versioning.adoc[]
16+
** xref:nifi:usage_guide/exposing-processors/index.adoc[]
17+
*** xref:nifi:usage_guide/exposing-processors/http.adoc[]
18+
*** xref:nifi:usage_guide/exposing-processors/tcp.adoc[]
1719
** xref:nifi:usage_guide/custom-components/index.adoc[]
1820
*** xref:nifi:usage_guide/custom-components/custom-nars.adoc[]
1921
*** xref:nifi:usage_guide/custom-components/custom-python-processors.adoc[]

0 commit comments

Comments
 (0)