Unravel › Java concepts › Messaging and Kafka
Spring Integration (channels and flows)
Spring Integration implements classic enterprise integration patterns in-process: messages travel over channels, and small components filter, transform, route, split and aggregate them.
Learn these first
At a glance
A conveyor-belt factory: every parcel is a message on a belt, and stations along the belt open it, relabel it, sort it to another belt or combine several into one.
- 1A Message<T> has a payload and headersA channel moves messages between components: DirectChannel calls the next step in the same thread, QueueChannel buffers messages for a poller.
- 2The Java DSL describes a flow fluently: IntegrationFlow.from("in").filter(...).transform(...).route(...).handle(...).get()
- 3@ServiceActivator marks a method that processes messages from a channel, @MessagingGateway creates a plain Java interface that hides the messaging behind a method call
- 4Adapters connect the outside world (files, FTP, JMS, AMQP, HTTP, Kafka, mail) so that a file appearing in a folder becomes a message in a flow
- A DirectChannel is synchronous: an exception in the last step reaches the sender, and a transaction on the sender covers the whole flow
- Every flow needs an error path
- Each DSL step creates a consumer endpoint bean
@Beanpublic IntegrationFlow orderFlow() { return IntegrationFlow.from("ordersIn") .filter(Order.class, o -> o.total().signum() > 0) .transform(Order.class, o -> new Invoice(o)) .handle(Invoice.class, (invoice, headers) -> { billing.send(invoice); return null; }) .get();}- line 2 uses IntegrationFlow, the core of Spring Integration (channels and flows)
- line 3 uses IntegrationFlow, the core of Spring Integration (channels and flows)
Read the full explanation (about 1 min)
Spring Integration implements classic enterprise integration patterns in-process: messages travel over channels, and small components filter, transform, route, split and aggregate them.
A mental model
A conveyor-belt factory: every parcel is a message on a belt, and stations along the belt open it, relabel it, sort it to another belt or combine several into one.
How it works
A Message<T> has a payload and headers. A channel moves messages between components: DirectChannel calls the next step in the same thread, QueueChannel buffers messages for a poller.
The Java DSL describes a flow fluently: IntegrationFlow.from("in").filter(...).transform(...).route(...).handle(...).get().
@ServiceActivator marks a method that processes messages from a channel, @MessagingGateway creates a plain Java interface that hides the messaging behind a method call.
Adapters connect the outside world (files, FTP, JMS, AMQP, HTTP, Kafka, mail) so that a file appearing in a folder becomes a message in a flow.
Going deeper
A DirectChannel is synchronous: an exception in the last step reaches the sender, and a transaction on the sender covers the whole flow. A QueueChannel or executor channel breaks both of those; plan error handling accordingly.
Every flow needs an error path. Unhandled exceptions in asynchronous channels go to the errorChannel, where nobody may be listening.
It is a heavy tool for simple needs. For one producer and one consumer, plain method calls or a message broker client are clearer.
Under the hood
Each DSL step creates a consumer endpoint bean. A subscriber on a DirectChannel is invoked by a dispatcher on the sender thread; polling endpoints use a TaskScheduler to pull from queue channels at a fixed rate. Headers such as replyChannel and errorChannel implement request-reply across the flow.
Common mistakes
- No error channel on asynchronous flows.
- Expecting a transaction to span queue channels.
- Overusing messaging for plain method calls.
- Unbounded queue channels.
How Unravel recognises it
When you paste code, Unravel looks for these signs of spring integration (channels and flows). Spotting them yourself is a good habit when you read unfamiliar code:
- Annotations:
@ServiceActivator@MessagingGateway@Transformer@Router@Splitter@Aggregator@InboundChannelAdapter@EnableIntegration@IntegrationComponentScan - Types:
IntegrationFlowIntegrationFlowsMessageChannelDirectChannelQueueChannelPublishSubscribeChannelMessageBuilderMessageHandlerPollableChannelPollersIntegrationFlowAdapter
Part of a learning path
- Scheduled jobs, batch and integration · previous: CSV and Excel file processing · next: Apache Camel integration routes
Related concepts
Frequently asked questions
What is Spring Integration (channels and flows)?
Spring Integration implements classic enterprise integration patterns in-process: messages travel over channels, and small components filter, transform, route, split and aggregate them.
What are the most common mistakes with Spring Integration (channels and flows)?
No error channel on asynchronous flows. Expecting a transaction to span queue channels. Overusing messaging for plain method calls. Unbounded queue channels.
How can I see Spring Integration (channels and flows) in real code?
Paste your own Java into Unravel and it will point out where spring integration (channels and flows) appears, explain how it works at the detail level you choose, and draw the flow of the code around it.