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
java
public class SlidingLogRateLimiter { private final int maxRequests; private final long windowMillis;
How a sliding-log rate limiter works
rate-limiting
concurrency
sliding-window
Advanced
8 steps
java
public final class Slugifier { private static final Pattern NON_LATIN = Pattern.compile("[^\\w-]"); private static final Pattern WHITESPACE = Pattern.compile("[\\s]+");
Building a URL slugifier in Java
regex
unicode-normalization
string-processing
Intermediate
8 steps
java
@Repository public interface OrderRepository extends JpaRepository<Order, Long> { @Query("""
Keyset pagination with Spring Data JPA
pagination
cursor
jpa
Advanced
8 steps
java
public record FixedWidthField(String name, int start, int end) { public String extract(String line) { int from = Math.min(start, line.length());
Parsing fixed-width text in Java
records
parsing
streams
Intermediate
7 steps
java
@RestController @RequestMapping("/api/quotes") public class QuoteStreamController {
Streaming market quotes with Spring WebFlux
reactive-streams
backpressure
server-sent-events
Advanced
9 steps
java
@Controller public class BookController { private final BookService bookService;
Solving GraphQL N+1 with batch mapping in Spring
graphql
n+1-problem
batching
Intermediate
8 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.