Compression Module in MuleSoft.
Pre-requisites
- We need to have an Anypoint Studio should be setup.
- We need to an order_table in database. For this instance, we are using the MySQL database.
- Create a table with the fields as ID, name, email, contact, status, and payment.
- We need to have some sample set of records in the database table, as shown in the table.
Compression Module
- The MuleSoft Compression Module provides out-of-the-box capabilities to compress and decompress files within your Mule applications.
- The specific use of this module is when integrating with systems that require or return large files, helping to reduce file size, optimize bandwidth, and simplify archiving.
- The compression module provides 4 different operations:
- Compress:
- This operation is used to compress a single file into the Zip or Gzip format.
- Decompress:
- This operation is used to decompress a single file from a specified format.
- Archive:
- This operation is used to compress multiple entries or files into a new archive file.
- Extract:
- This operation is used to decompress the archived content.
- Compress:
- Let’s understand this component with a requirement. We need to design a scheduled process to synchronize Customer data from a MySQL database to the local file system. This process will exclusively retrieve Customer records from the MySQL DB based on the status “Yes”, consolidate them into a single file, compress the file into a ZIP archive send it over mail, and after that update the status “Completed”. The automation is scheduled to run daily at 11:00 AM IST, ensuring timely and consistent data synchronization.
Steps:
- To begin, a new Mule project needs to be created. Then, drag and drop the Scheduler and configure the cron expression as “0 0 11 * * *” and the time zone with “Asia/Calcutta”.
- Next, add the start logger and end logger, which determine the start and end of the flow. By configuring the logger with “Start of flow ” ++ (flow.name as String)
- Next, we’ll add a Database Select operation to our flow and configure it to query the required data. To ensure security, we’ll reference the database connection details using secure property placeholders, which allows us to keep sensitive credentials encrypted and externalized from the main codebase.

- Next, we’ll incorporate a database query to retrieve records where the status flag is set to “Yes.” To enhance flexibility and maintainability, we’ll use configuration properties to dynamically fetch the value of the status field, making the solution easily adaptable across environments.

- Then, we’ll drag and drop a transform message component to transform the payload into JSON format and create a variable “consolidated record”, having value as an empty array.
- Next, we’ll make use of a choice router to process the records only if the payment is completed and wrap in for-each to iterate over the records.
- Next, we’ll consolidate the records and store them in “consolidated records” variable.
- Next, we’ll add a choice router to check for the variable consolidated records is not empty.
- Then, we’ll add the compress component which will compress the records.
- Next, we’ll use the Mail Connector’s Send component to email the consolidated records as a zipped attachment.
- Then, we’ll update the Status as ‘Completed’ using a bulk update. To do so, we’ll configure the query with the following syntax: Update Customer set Status=: Status where ID=:ID and use the input parameters from the variable consolidated records.
- The setup is ready to be deployed.
- Lastly, we’ll verify the mail received and DB, with the updated value for the records.
Ready to simplify your data workflows with smart automation? Connect with TGH’s MuleSoft experts to compress, archive, and email your database records effortlessly. Get started today!
















