Spring Integration notes

Introduction

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:

  1. Message
  2. Channel
  3. Endpoint

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.

https://www.enterpriseintegrationpatterns.com/patterns/messaging/

Message

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.).


https://docs.spring.io/spring-integration/docs/current/reference/html/#overview-components-message

Messages are very generic so they may deliver many types of payload:

  • String
  • Object
  • XML
  • JSON
  • SOAP etc.

Object has no setter methods so the message is immutable.

Channels 

Using channels to deliver messages between endpoints keeps the endpoints unaware of each other. So channels are the key to flexibility in SI.

Endpoints

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.

Channels

Channel types control how messages are received. 

There are 2 primary types of channels:

  1. PollableChannel
  2. SubscribableChannel

Base channel interface is MessageChannel.

PollableChannel

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:

QueueChannel

A FIFO channel. Even if the channel has multiple consumers, only one of them should receive any Message sent to that channel.

PriorityQueueChannel

Messages polled based on their priority

SubscribableChannel

Allow endpoints to request to be notified when a message is received.

DirectChannel

The most basic type in SI. Implements SubscribableChannel. Allows for communication between 1 Producer and 1 Consumer.

PublishSubscribeChannel

Allows for multiple consumers of a message. One message is sent to all consumers. Suitable for event-type notifications.

Message Endpoints

Message Transformer

Endpoint responsible for converting message content or structure and returning the modified message (both for headers or payload).

Implementations of org.springframework.integration.transformer.Transformer

Message Filter

Filters messages flowing between two channels.

Message Router

Decides what channels or channel or if any channel at all should receive the message.


https://www.enterpriseintegrationpatterns.com/patterns/messaging/MessageRouter.html

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.

Splitter endpoint

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.


https://www.enterpriseintegrationpatterns.com/patterns/messaging/Sequencer.html

Aggregator endpoint

The opposite of the Splitter.

Service activator

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.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.