DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Trending

  • When Airflow Tasks Get Stuck in Queued: A Real-World Debugging Story
  • The Future of Java and AI: Coding in 2025
  • Implementing Explainable AI in CRM Using Stream Processing
  • Distributed Consensus: Paxos vs. Raft and Modern Implementations

Compression Module Mule 4

By 
Riddhi Thacker user avatar
Riddhi Thacker
DZone Core CORE ·
Vikalp Bhalia user avatar
Vikalp Bhalia
DZone Core CORE ·
Sep. 16, 20 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
14.4K Views

Join the DZone community and get the full member experience.

Join For Free

Whenever there is a large file or more than one file, we use tools like 7zip, WinZip to compress or create a zip file, and similarly, we decompress or unzip the file.

But what if we have a similar requirement in an Integration project?

Mule 4 comes with a Compression Module which can:

  • Compress/Decompress a file or payload
  • Zip/Unzip files

NOTE: Github repository with the Mule Project can be found at the end of the post. 

Configuration

To add the Compression Module in the Mule Palate:

  • Click on "Search on Exchange" 
  • Search for Compression Module
  • Click on add and finish.
    Adding dependency to project

Once you complete the above steps you will be able to see the Compression Module in the Mule Palate

Mule Palate

Operations

Archive/Extract

Archive and Extract are the functions used to zip and unzip the files respectively.

Archive

This operation accepts a map where the key is the file name and value is content.

Example:

JSON
x
 
1
{
2
    "files/csv.txt": vars.csvText,
3
    "files/html.txt": vars.htmlText,
4
    "files/json.txt": vars.jsonText,
5
    "files/zip.txt": vars.zipText
6
}


Below is the screenshot of the flow.

Application workflow
The above flow will create an archive having 4 files in a files folder.

Plain Text
 




xxxxxxxxxx
1


 
1
+ zipped-file
2
  + files
3
    - csv.txt
4
    - html.txt
5
    - json.txt
6
    - zip.txt



Extract

This operation accepts an archived file and returns a map.

Plain Text
 




x


 
1
{
2
    "files/csv.txt": "File content",
3
    "files/html.txt": "File content",
4
    "files/json.txt": "File content",
5
    "files/zip.txt": "File content"
6
}



And the below code will convert the object in an array.

Java
 




xxxxxxxxxx
1


 
1
payload pluck {
2
    fileName: $$,
3
    content: $
4
}



Below is the screenshot of the flow.

unzip workflow

Errors

Archive

  • COMPRESSION:COULD_NOT_COMPRESS – if any error occurs while compressing the content

Extract

  • COMPRESSION:INVALID_ARCHIVE – If the content is not in the configured format
  • COMPRESSION:COULD_NOT_DECOMPRESS – Other errors occurred during compression process


Compress/Decompress

The compress and decompress are straight forward.

Compress

The module provides 2 compressor techniques:

  • Zip Compressor.
  • GZip Compressor.

Below is the sample flow:

Compression workflow

Decompress

Select the same compressor technique which was used to compress the file.

Below is the sample flow:

Decompression workflow


Conclusion

If you are dealing with a large payload or if you have a size limit on payload transfer or you need to extract some file or create a zip file, the Compression module is a good fit.

Github Repository

compression-module-demo

Opinions expressed by DZone contributors are their own.

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!