Gzip Compress & Gzip Uncompress Transformer in Mule

  Gzip Compress & Gzip Uncompress Transformer in Mule




How to compress & uncompress a file in mule ?
We can do it by Gzip Compress & Gzip Uncompress Transformers in Mulesoft.

Gzip Compress Transformer : It compress byte array or file.We can reduce file size by this transformer.

Gzip Uncompress Transformer : It is used to uncompress byte array or a file and restored it back in original size.

The Compression module supports and provides access to the most-used file archiver and compression formats through a Mule app.


A file archiver is a computer program that combines a number of files together into one archive file for easier transportation or storage, and most archivers employ data compression in their archive formats to reduce the size of the final archive. However, not all compression algorithms can archive multiple files. Some are limited to single-file data compression.

This module compresses and decompresses files for each of the available formats without losing any of the features that the format associated algorithm provides.
To achieve this capability, the module provides two pairs of operations, one for compressing and decompressing a single file, another for archiving and extracting a bundle of files. Each of these operations can be configured with the compression or archiving strategies of your choice.

flow of Compress & Gzip Uncompress Transformer :





In above flow, a file is compressed by Gzip Compress transformer and stored in output folder of src/main/resources. In second flow, file connector picks that compressed file and uncompress that by Gzip Uncompress transformer.We can compare file size of both the files in file's properties.

All files are in src/main/resources :



XML project code :



<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
    <file:connector name="File" outputPattern="output.json" writeToDirectory="src/main/resources/output" autoDelete="false" streaming="false" validateConnections="true" doc:name="File"/>
    <file:connector name="File2" outputPattern="original_input.json" autoDelete="false" streaming="false" validateConnections="true" doc:name="File" writeToDirectory="src/main/resources/uncompressed"/>
    <file:connector name="File1" outputPattern="input.json" writeToDirectory="src/main/resources/input" autoDelete="false" streaming="false" validateConnections="true" doc:name="File"/>
    <flow name="test_objecttostringFlow">
        <file:inbound-endpoint path="src/main/resources/input" connector-ref="File1" responseTimeout="10000" doc:name="File"/>
        <gzip-compress-transformer doc:name="Gzip Compress"/>
        <file:outbound-endpoint path="src/main/resources/output" outputPattern="output.json" connector-ref="File" responseTimeout="10000" doc:name="File"/>
    </flow>
    <flow name="test_gzipcompressFlow">
        <file:inbound-endpoint path="src/main/resources/output" connector-ref="File" responseTimeout="10000" doc:name="File"/>
        <gzip-uncompress-transformer doc:name="Gzip Uncompress"/>
        <file:outbound-endpoint path="src/main/resources/uncompressed" outputPattern="original_input.json" connector-ref="File2" responseTimeout="10000" doc:name="File"/>
    </flow>
</mule>



Please go through below tutorials:


Mule 4 Tutorials

DEPLOY TO CLOUDHUB C4E CLIENT ID ENFORCEMENT CUSTOM POLICY RABBIT MQ INTEGRATION
XML TO JSON WEBSERVICE CONSUMER VM CONNECTOR VALIDATION UNTIL SUCCESSFUL
SUB FLOW SET & REMOVE VARIABLE TRANSACTION ID SCATTER GATHER ROUND ROBIN
CONSUME REST WEBSERVICE CRUD OPERATIONS PARSE TEMPLATE OBJECT TO JSON LOAD STATIC RESOURCE
JSON TO XML INVOKE IDEMPOTENT FILTER FOR EACH FLAT TO JSON
FIXWIDTH TO JSON FIRST SUCCESSFUL FILE OPERATIONS EXECUTE ERROR HANDLING
EMAIL FUNCTIONALITY DYNAMIC EVALUATE CUSTOM BUSINESS EVENT CSV TO JSON COPYBOOK TO JSON
CHOICE ASYNC

Widely used Connectors in Mule 3

CMIS JETTY VM CONNECTOR SALESFORCE POP3
JMS TCP/IP WEBSERVICE CONSUMER QUARTZ MONGO DB
FILE CONNECTOR DATABASE CONNECTOR


Widely used Scopes in Mule 3

SUB FLOW REQUEST REPLY PROCESSOR CHAIN FOR EACH CACHE
ASYNC TCP/IP COMPOSITE SOURCE POLL UNTIL SUCCESSFUL
TRANSACTIONAL FLOW

Widely used Components in Mule 3

EXPRESSION CXF SCRIPT RUBY PYTHON
JAVASCRIPT JAVA INVOKE CUSTOM BUSINESS EVENT GROOVY
ECHO LOGGER


Widely used Transformers in Mule 3

MONGO DB XSLT TRANSFORMER REFERENCE SCRIPT RUBY
PYTHON MESSAGE PROPERTIES JAVA TRANSFORMER GZIP COMPRESS/UNCOMPRESS GROOVY
EXPRESSION DOM TO XML STRING VALIDATION COMBINE COLLECTIONS BYTE ARRAY TO STRING
ATTACHMENT TRANSFORMER FILE TO STRING XML TO DOM APPEND STRING JAVASCRIPT
JSON TO JAVA COPYBOOK TO JSON MAP TO JSON JSON TO XML FLATFILE TO JSON
FIXWIDTH TO JSON CSV TO JSON


Widely used Filters in Mule 3

WILDCARD SCHEMA VALIDATION REGEX PAYLOAD OR
NOT MESSAGE PROPERTY MESSAGE IDEMPOTENT FILTER REFERNCE
EXPRESSION EXCEPTION CUSTOM AND


Exception Strategy in Mule 3

REFERENCE EXCEPTION STRATEGY CUSTOM EXCEPTION STRATEGY CHOICE EXCEPTION STRATEGY CATCH EXCEPTION STRATEGY GLOBAL EXCEPTION STRATEGY


Flow Control in Mule 3

CHOICE COLLECTION AGGREGATOR COLLECTION SPLITTER CUSTOM AGGREGATOR FIRST SUCCESSFUL
MESSAGE CHUNK AGGREGATOR MESSAGE CHUNK SPLITTER RESEQUENCER ROUND ROBIN SOAP ROUTER