DEV Community

WB
WB

Posted on • Updated on

Hello Mule (Mulesoft)

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

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
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

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

Image description
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

Select the connector to activate its configuration:

Image description

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

Image description

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

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

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

Image description

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

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

Image description

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

Image description

Create a file test.txt and drop it into the inbox directory. The file will be moved automatically to the outboxdirectory 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.

Top comments (0)