liveBook · Manning

@Router

As explained in Spring in Action, Sixth Edition

@Router is a Spring Integration annotation that identifies a method or bean as defining message-routing behavior.

@Router marks a Spring Integration bean as a router: it examines a message and directs it to one of several channels according to routing criteria. section 10.2 section 10.2.4

A router can be implemented in several practical ways:

  • Declare an AbstractMessageRouter bean with @Router and return the target channel for each message. section 10.2.4
  • Route even and odd integers from numberChannel to evenChannel or oddChannel by inspecting the payload. section 10.2.4
  • Use a PayloadTypeRouter after a splitter to send BillingInfo and List payloads to different channels. section 10.2.5
  • In Java DSL, call route() and map returned values such as EVEN and ODD to separate subflows. section 10.2.4

Even-and-odd message routing

An @Router bean receives messages from numberChannel, reads the integer payload, and returns evenChannel for even numbers or oddChannel for odd numbers. Each channel can then continue with its own processing flow.

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains annotated beans, payload inspection, channel mapping, and Java DSL routing, without covering router internals.
Examples
Uses even-and-odd integer channels, Java DSL subflows, and purchase-order payload routing for BillingInfo and List values.
What it assumes
Assumes messages, channels, and integration flows while introducing routing through concrete payload and channel examples.
What you can do after
Build message branches with @Router, AbstractMessageRouter, PayloadTypeRouter, or Java DSL route() mappings.
How it connects
Connects routers with integration flows, message channels, splitters, payload types, and Java DSL subflows.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.