Different Streaming Strategies in Mule 4
We will go through one of the most important concepts of MuleSoft Streaming strategies. There are 3 types of streaming strategies available in MuleSoft.
Join the DZone community and get the full member experience.Join For Free
In this article, we will go through one of the most important concepts of MuleSoft Streaming strategies.
There are three types of streaming strategies available in MuleSoft:
- Repeatable file store stream (by default, this strategy is selected).
- Non repeatable stream.
- Repeatable in-memory stream.
Following is the snippet for the same:
Let us try to understand each one of them step by step:
Repeatable File Store Stream
This streaming strategy is selected by default.
Before proceeding, let us consider a simple scenario like we have 0.1vCore (512MB memory) and our application is deployed, what will happen if you pass 1 GB of payload. Will it throw some exception or will execute successfully?
If you think, it will execute successfully then you are right, because by default 'Repeatable file store stream' strategy is selected.
How Does It Work?
In reality, for 0.1 vCore there is 8GB of memory available, what MuleSoft provides to us is 512 MB as Heap memory. After 512 MB is full, data will be stored in the disk storage which is the remaining memory (8GB - 512MB (some installations let us assume 1.5 GB)).
Following are some of the advantages:
- As it stores data in the memory and disk, so you can pass input payload of more size than heap size.
- As the name suggests repeatable, once you read the data, and you want to read the same data somewhere else you can read that as data is backed up in disk storage.
Non Repeatable Stream
In this streaming strategy, when the very first time you are reading the input payload, the memory assignment and everything work as Repeatable File Stream strategy but once read, the payload data will be cleared from the memory and disk space, and you cannot read it again.
Repeatable In-Memory Stream
This streaming strategy is a bit different from others. In this, the data will be stored in memory (heap memory), it will not be stored in disk space. So if you pass payload more than heap size, it will throw memory out of bound exception.
We here learned different streaming strategies like Repeatable file store, Non-Repeatable, Repeatable Stream.
Opinions expressed by DZone contributors are their own.