Skip to content

mule-chunking-connector

Stream large binary files into chunks for streaming processing in mule, maintaining constant memory regardless of the size of the incoming stream.

Features

  • True streaming: uses one chunk of memory plus a small overhead
  • Lazy iteration: Chunks read on-demand
  • Raw binary: No encoding overhead - direct byte[] access

Usage

Basic Example

xml
<!-- Read large file -->
<file:read path="/path/to/large-file.bin"/>

<!-- Chunk into pieces -->
<chunking:read-chunked chunkSize="5242880"/>

<!-- Process each chunk with constant memory -->
<foreach>
    <logger message="Chunk #[payload.index]: #[payload.length] bytes"/>

    <!-- Example: S3 multipart upload -->
    <s3:upload-part
        partNumber="#[payload.index + 1]"
        content="#[payload.data]"/>
</foreach>

Configuration

xml
<chunking:config name="Chunking_Config">
    <chunking:connection/>
</chunking:config>

Operation: read-chunked

ParameterTypeDefaultDescription
chunkSizeInteger65536 (64KB)Size of each chunk in bytes
contentInputStreampayloadBinary content to chunk

Chunk Properties

Each chunk has these properties:

PropertyTypeDescription
payload.databyte[]Raw binary chunk data
payload.indexint0-based chunk number
payload.offsetlongByte position in source
payload.lengthintBytes in this chunk
payload.isFirstbooleanTrue for first chunk
payload.isLastbooleanTrue for final chunk

DataWeave Examples

dataweave
// Get chunk number (1-based for APIs)
payload.index + 1

// Check if processing last chunk
payload.isLast

Installation

Add to your Mule project's pom.xml:

xml
<dependency>
    <groupId>com.mulesoftforge</groupId>
    <artifactId>mule-chunking-connector</artifactId>
    <version>0.1.0</version>
    <classifier>mule-plugin</classifier>
</dependency>

Use Cases

  • S3 Multipart Upload: Split large files for parallel upload
  • Streaming ETL: Process large files without loading into memory
  • Checksum Calculation: Hash files in chunks
  • Network Transfer: Send large files in manageable pieces

Requirements

  • Mule Runtime 4.9.0 or later
  • Java 17

Learn More

Released under the MIT License.