Routers
One of the flow requirements is to send the messages to one or more
channels based on certain criteria. A router component can be used to
distribute the messages to multiple destinations. For example, the
requirement is that all new Trades should be sent to new-trades-in-channel while all amended Trades
are sent to amended-trades-in-channel.
The Router component will take care of
this task. The router picks up the message from a channel and redelivers
(routes) it to the relevant channel based on payload or
headers content.
There is a difference between the filters and routers. While Filter decides whether or not the message is to be sent based on a simple Boolean test, Router forwards the message to one or more channels based on content. There are only two options for a message that’s being passed through a Filter—forwarded or discarded. If a filter is used, a message may or may not appear in an output channel, whereas if a router is used, a single message can be sent to one or more channels.
The framework provides a couple of built-in routers: PayloadTypeRouter, based on
payload content, or HeaderValueRouter, based on
header values.
PayloadTypeRouter
The PayloadTypeRouter
determines the routing of messages to different channels based on the
type of the payload. The router
endpoint attached to an incoming channel will evaluate the type and
accordingly distribute (route) the messages to other channels expecting
that particular type. The payload-type-router element is used to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access