Contact Us 1-800-596-4880

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:

  1. In Anypoint Studio, click File > New > Mule Project, name the project, and click Finish.

  2. In the Mule Palette search field, type http.

  3. Drag the HTTP > Listener operation to the canvas.

  4. In General settings, click the green plus sign (+) to the right of Connector Configuration.

  5. Click OK to accept the default settings.

  6. In Path, enter /createFile.

  7. In the Mule Palette search field, type hdfs.

  8. Drag the HDFS Write operation to the canvas.

  9. Set Path to /test.txt and leave the default values for the other options.
    This is the path of the file that HDFS creates.

  10. Right-click in the project canvas and select Run project to start the application.

  11. From an HTTP client such as Postman or curl, make a POST request, set the value for Content-type:plain/text to localhost: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

  12. Use an HDFS explorer to verify that the /test.txt file exists and contains your content.

View on GitHub