Table of Contents
Channels are used for routing messages to endpoints.
Channels do the routing and endpoints perform the operations.
Spring Integration (SI) provides numerous adapters for communication between different systems.
SI uses 3 types of components to construct its messaging architecture:
Endpoint > Channel (passes a Message) > Endpoint
Spring Integration mirrors everything from “Enterprise Integration Patterns”; so If you’re familiar with those you can easily understand the concepts used in SI.
A piece of information passed between 2 components.
Wraps any object used by SI. Object wrapped by message is called payload.
There may be also some headers that describe the message being sent (ex. ids, timestamps etc.).
Messages are very generic so they may deliver many types of payload:
- SOAP etc.
Object has no setter methods so the message is immutable.
Using channels to deliver messages between endpoints keeps the endpoints unaware of each other. So channels are the key to flexibility in SI.
Endpoints perform some operation when the message is received.
Consumer or producer simply describe the side of the channel an endpoint resides at.
Producers place messages on a channel to be delivered to a consumer that receives it.
Adapters and gateways are special types of endpoints used for connecting between 2 applications via some particular protocol – this usage of specific protocols is transparent for application using SI.
There may be also communication between a single application components and in that case messaging is used.
Channel types control how messages are received.
There are 2 primary types of channels:
Base channel interface is MessageChannel.
This interface defines channel that allows for messages to be delivered on request from a buffer by invoking the receive() method. So application runs asynchronously as it won’t wait for a response from the consumer.
The advantage of buffering is that it allows for throttling the inbound messages and thereby prevents overloading a consumer.
Buffer is received from a producer.
Implementations of PollableChannel:
A FIFO channel. Even if the channel has multiple consumers, only one of them should receive any Message sent to that channel.
Messages polled based on their priority
Allow endpoints to request to be notified when a message is received.
The most basic type in SI. Implements SubscribableChannel. Allows for communication between 1 Producer and 1 Consumer.
Allows for multiple consumers of a message. One message is sent to all consumers. Suitable for event-type notifications.
Endpoint responsible for converting message content or structure and returning the modified message (both for headers or payload).
Filters messages flowing between two channels.
Decides what channels or channel or if any channel at all should receive the message.
A key property of the Message Router is that it does not modify the message contents. It only concerns itself with the destination of the message.
Single input channel and single output channel. Splits the message from input channel and sends it in parts (as separate messages) to the output channel.
The opposite of the Splitter.
Imagine you need to call an external service that has nothing to do with messaging. In that case you may use a Service Activator – it receives the request message by input channel, makes a call to the external service according to that message and if you are expecting a response from that service it would also build a response message which will be sent as a reply using the output channel.
Channel Adapter endpoint
Works like a converter that allows for call from/to external system to be converted to/from messages that will flow by channels defined in Spring Integration app.