Hello Mule (Mulesoft)
Tags: integration, apachecamel, mulesofthackathon, springintegration
Published: 2023-12-21 19:39:19

This post is the first of a series of articles about system integration in the enterprise. We will approach the topic from first principles and gradually expand into real world scenarios. 
## What is System Integration?
System integration is everything. Anytime 2 "things" need to communicate with eachother, they are actually "integrating" with one another. Over the years, system integration has come to mean the process of integrating heterogeneous systems. These are systems that have clear boundaries between eachother, usually built by different teams to address different concerns, but need to talk to eachother by exchanging messages. A data warehouse system (DWS) may need to be aware of all the items that were ordered during the day for analytics purposes. An oder-management system (OMS) will then have to report the relevant data to the DWS. There need to be a way to exchange messages between the 2 systems in a reliable and robust way. One tried and tested solution is the use of files as exchange mechanism. Here we have an inbox directory, in which the OMS will drop the files with the list of items sold during the day, and the DWS will read them for processing.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uf094gk1ilv3ys9vep6b.png)

In the next section, we will implement a solution to this simple yet intricate process. We will start with a local file exchange and then continue with a SFTP Server.

## Mule
System Integration is difficult to implement right. There are a lot of great tools available on the market to help make the task of the system integrator easy. Some of the tools will be touched in this blogs serie, but the main focus will be on Mule, and sometimes we will compare the Mule solution with Apache Camel or Spring Integration. 

## Hello Mule
File exchange is the "helloworld" of system integration. Let's implement files exchange with [Anypoint Studio](https://anypoint.mulesoft.com)
If you have ever worked with eclipse before, you will feel right at home because anypoint studio is based on the eclipse platform.
Let's jump right into it:

Go to 
File -> New -> Mule Project


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h0wb2a80hunw6u7inyh7.png)



In the "Mule Palette", enter "File" in the search box.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s95qfj6ucmebq6sluykv.png)
You will get the list of file connectors available. The one we are going to use, is the "On new or Updated File". This connector will monitor a directory for any new or updated file and trigger processing. Drag and drop it on the blank canvas
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/64w78yxr1hr6mbbu1yxt.png)

Select the connector to activate its configuration:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o26rc2ch5xhofpsxm4s4.png)

Under "Basic Settings", add a new connector configuration by clicking the + button.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qwk8nufgc5pmn74j89qe.png)

Choose a working directory on your machine and click "Ok". I have created mine under `C:\dev\Mulesoft\tutorial`
In the "General" configuration panel, set the directory to "inbox", the Matcher to "Edit inline" and the filename pattern to "*.txt"

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xu3hvrvfx15s0kj76uuc.png)

Mule will be watching for *.txt files in the directory `C:\dev\Mulesoft\tutorial\inbox`. You have to make sure that you have created the `inbox` directory.

Scroll down and locate the Scheduling Strategy. Make sure it is "Fixed frequency". Leave "Frequency" to 1000 and TimeUnit to MILLISECONDS. Mule will be monitory the `inbox` directory every 1000 milliseconds (1 second).

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ejvhyjlic8olymajn91.png)

Scroll down to the "Post processing action" section and enter directory to move the *.txt files to. Make sure that directory exists.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yxivnsjs4hy62o2s9a2q.png)

We are almost ready to test our application. What is missing is a processor that will process the files as they are being read from the inbox directory. We are going to add a simple Logger which purpose is to output the content of the file that are being loaded by mule.
In the "Mule Palette", enter "logger"

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q6xwaxc2k0bbp3j580a7.png)

Select the "Logger" processor and drag and drop into the flow after the file connector.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ys3ypxtebx38g0xjxkh.png)

Right click the canvas and select `Run project`. Wait until the application has been deployed by looking in the Console.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uxl6zobjj1qmope3xvm4.png)


Create a file `test.txt` and drop it into the `inbox` directory. The file will be moved automatically to the `outbox`directory by the mule application.
In the console window, observe how the Logger processor is logging the file read from the inbox directory.

If you have made it to this point, congratulations. In the next posts, we will look into unit testing the application with MUnit. We will also show how to read the content of the file.
Stay tuned.