java
33 lines · 9 steps
Building an order pipeline with Spring Integration
A Spring Integration flow validates, transforms, and reserves orders as messages travel through channels.
Explained by
highlit
1@Configuration
2@EnableIntegration
3public class OrderProcessingFlow {
4
5 @Bean
6 public MessageChannel incomingOrders() {
7 return MessageChannels.direct().getObject();
8 }
9
10 @Bean
11 public IntegrationFlow orderFlow(OrderValidator validator, InventoryService inventory) {
12 return IntegrationFlow.from(incomingOrders())
13 .filter(Order.class, order -> order.getTotal().signum() > 0,
14 f -> f.discardChannel("rejectedOrders"))
15 .transform(Order.class, validator::normalize)
16 .handle(Order.class, (order, headers) -> {
17 inventory.reserve(order.getSku(), order.getQuantity());
18 return order.withStatus(OrderStatus.RESERVED);
19 })
20 .enrichHeaders(h -> h.header("processedAt", Instant.now().toString()))
21 .channel("confirmedOrders")
22 .get();
23 }
24
25 @Bean
26 public IntegrationFlow confirmationFlow(NotificationGateway gateway) {
27 return IntegrationFlow.from("confirmedOrders")
28 .<Order, String>transform(order ->
29 "Order %s reserved for %s".formatted(order.getId(), order.getCustomer()))
30 .handle(gateway)
31 .get();
32 }
33}
01 / 01
STEP 01
‹ swipe to step through ›
Walkthrough
Space play
←→ step
click any line
Three takeaways
- 1Spring Integration models processing as messages moving through composable channels rather than direct method calls.
- 2Each stage (filter, transform, handle) has a single responsibility, keeping the pipeline readable and easy to extend.
- 3Named channels let independent flows hand work off to each other, decoupling producers from consumers.
Related explainers
go
package streaming import ( "bufio"
Streaming NDJSON logs over HTTP in Go
http-streaming
channels
select
Advanced
10 steps
php
<?php namespace App\Services\Checkout;
Validating coupons with Laravel's Pipeline
pipeline
chain of responsibility
transactions
Intermediate
7 steps
java
@Component @Converter public class EncryptedStringConverter implements AttributeConverter<String, String> {
Transparent column encryption in Spring & JPA
encryption
aes-gcm
jpa-converter
Advanced
10 steps
java
package com.acme.billing.config; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.ConfigurationProperties;
Feature-flagged beans with Spring @ConditionalOnProperty
feature-flags
conditional-beans
strategy-pattern
Intermediate
5 steps
go
func (w *Watcher) resetDebounce(d time.Duration) { if !w.timer.Stop() { select { case <-w.timer.C:
Debouncing a stream of events in Go
debounce
timers
channels
Advanced
7 steps
java
public static Map<String, String> parseCookieHeader(String header) { Map<String, String> cookies = new LinkedHashMap<>(); if (header == null || header.isBlank()) { return cookies;
Parsing an HTTP Cookie header in Java
string-parsing
http
url-decoding
Intermediate
6 steps
Share this explainer
Here's the card — post it anywhere.
Made with highlit — turn any snippet into a walkthrough like this in about a minute.
Explain your code
Embed this explainer
Drop the interactive walkthrough into a blog or docs. Views never cost a credit.
<iframe src="https://highlit.co/explainers/building-an-order-pipeline-with-spring-integration-explained-java-f1c8/embed?autoplay=1" width="100%" height="520" loading="lazy" style="border:0"></iframe>
Autoplay is on by default — add ?autoplay=0 to start paused.