Hadoop (HDFS) Connector - Examples - Mule 4
Create a Text File in HDFS
The following example shows how to use the connector to create a text file in HDFS:
-
In Anypoint Studio, click File > New > Mule Project, name the project, and click Finish.
-
In the Mule Palette search field, type
http
. -
Drag the HTTP > Listener operation to the canvas.
-
In General settings, click the green plus sign (+) to the right of Connector Configuration.
-
Click OK to accept the default settings.
-
In Path, enter
/createFile
. -
In the Mule Palette search field, type
hdfs
. -
Drag the HDFS Write operation to the canvas.
-
Set Path to
/test.txt
and leave the default values for the other options.
This is the path of the file that HDFS creates. -
Right-click in the project canvas and select Run project to start the application.
-
From an HTTP client such as Postman or curl, make a POST request, set the value for
Content-type:plain/text
tolocalhost:8081/createFile
, and add the content you want to write as a payload, as shown in the following example:
curl -X POST -H "Content-Type:plain/text" -d "payload to write to file" localhost:8090/createFile
-
Use an HDFS explorer to verify that the
/test.txt
file exists and contains your content.