Splitters

Splitters are used to split a message into pieces. The message will be dissected into smaller ones by custom logic for various consumers to act on. There are several scenarios for using splitters, such as splitting a large payload into smaller chunks or introducing parallel processing. The Spring Integration framework provides a splitter element into the integration namespace. The element will then refer to a splitter bean which implements the splitting logic.

You can implement splitter in various ways: you can either implement your own POJO with custom logic or extend Framework’s AbstractMessageSplitter abstract class to implement the splitMessage() method. You can also use Annotations to define one.

Using Custom Splitters

If you choose to use custom splitters, all you have to do is create a simple POJO that implements the splitting algorithm.

Let’s take an example of an incoming message consisting of a normal Trade and some encrypted data. The requirement is to extract this encrypted message into a different object, EncryptedTrade. The newly created EncryptedTrade and the old (original) Trade will be sent out to the output channel. The output channel will receive two messages, one which is a normal Trade with no encrypted message and a second message with the encrypted message represented by EncryptedTrade object. The preferred way to do this is to introduce a splitter component to split the incoming message into two Trades.

Trade and EncryptedTrade both inherit from ITrade ...

Get Just Spring Integration now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.