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

Walkthrough

Space play step click any line
Three takeaways
  1. 1Spring Integration models processing as messages moving through composable channels rather than direct method calls.
  2. 2Each stage (filter, transform, handle) has a single responsibility, keeping the pipeline readable and easy to extend.
  3. 3Named channels let independent flows hand work off to each other, decoupling producers from consumers.

Related explainers

Share this explainer

Here's the card — post it anywhere.

Building an order pipeline with Spring Integration — share card
Made with highlit — turn any snippet into a walkthrough like this in about a minute.
Explain your code