--- url: "http://www.enterpriseintegrationpatterns.com/MessageRoutingIntro.html" titulek: "Introduction to Message Routing - Enterprise Integration Patterns" h1: "" popis: "In Chapter 2, we discussed how a Message Router can be used to decouple a message source from the ultimate destination of the message. This chapter elaborates on specific types of Message Routers to explain how to provide routing and brokering ability to an integration solution. Most patterns are refinements of the Message Router pattern while others combine multiple Message Routers to solve more complex problems. Therefore, we can categorize the Message Routing patterns into the following groups:" jazyk: "en" kanonicka: "" drobecky: [] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-15 15:34:10" znaku: 12657 slov: 1559 kodovani: "utf-8" sha256: "17ec81524f67e57023db779842ba8018132255c63006c9b3ea7301a90cf5dd6d" --- | | Introduction to Message Routing[Messaging Patterns](index.html) » [Message Routing](MessageRoutingIntro.html) | [Contents](toc.html)[⇐ Prev](ObserverJmsExample.html)[Next ⇒](ContentBasedRouter.html) | | --- | --- | --- | In Chapter 2, we discussed how a [*Message Router*](MessageRouter.html) can be used to decouple a message source from the ultimate destination of the message. This chapter elaborates on specific types of [*Message Router*](MessageRouter.html)s to explain how to provide routing and brokering ability to an integration solution. Most patterns are refinements of the [*Message Router*](MessageRouter.html) pattern while others combine multiple [*Message Router*](MessageRouter.html)s to solve more complex problems. Therefore, we can categorize the Message Routing patterns into the following groups: - **Simple Routers** are variants of the [*Message Router*](MessageRouter.html) and route messages from one inbound channel to one or more outbound channels. - **Composed Routers** combine multiple simple routers to create more complex message flows. - **Architectural Patterns** describe architectural styles based on [*Message Router*](MessageRouter.html) s. ## Simple Routers The [*Content-Based Router*](ContentBasedRouter.html) inspects the content of a message and routes it to another channel based on the content of the message. Using such a router enables the message producer to send messages to a single channel and leave it to the [*Content-Based Router*](ContentBasedRouter.html) to inspect messages and route them to the proper destination. This alleviates the sending application from this task and avoids coupling the message producer to specific destination channels. A [*Message Filter*](Filter.html) is a special form of a [*Content-Based Router*](ContentBasedRouter.html). It examines the message content and passes the message to another channel if the message content matches certain criteria. Otherwise, it discards the message. [*Message Filter*](Filter.html)s can be used with [*Publish-Subscribe Channel*](PublishSubscribeChannel.html) to route a message to all possible recipients and allow the recipients to filter out irrelevant messages. A [*Message Filter*](Filter.html) performs a function that is very similar to that of a [*Selective Consumer*](MessageSelector.html) with the key difference being that a [*Message Filter*](Filter.html) is part of the messaging system, routing qualifying messages to another channel, whereas a [*Selective Consumer*](MessageSelector.html) is built into a [*Message Endpoint*](MessageEndpoint.html). A [*Content-Based Router*](ContentBasedRouter.html) and a [*Message Filter*](Filter.html) can actually solve a similar problem. A [*Content-Based Router*](ContentBasedRouter.html) routes a message to the correct destination based on the criteria encoded in the [*Content-Based Router*](ContentBasedRouter.html). Equivalent behavior can be achieved by using a [*Publish-Subscribe Channel*](PublishSubscribeChannel.html) and an array of [*Message Filter*](Filter.html)s, one for each potential recipient. Each [*Message Filter*](Filter.html) eliminates the messages that to not match the criteria for the specific destination. The [*Content-Based Router*](ContentBasedRouter.html) routes predictively to a single channel and therefore has total control, but is also dependent on the list of all possible destination channels. The [*Message Filter*](Filter.html) array filters reactively, spreading the routing logic across many [*Message Filter*](Filter.html)s but avoiding a single component that is dependent on all possible destinations. The trade-off between these solutions is described in more detail in the [*Message Filter*](Filter.html) pattern. A basic [*Message Router*](MessageRouter.html) uses fixed rules to determine the destination of an incoming message. Where we need more flexibility, a [*Dynamic Router*](DynamicRouter.html) can be very useful. This router allows the routing logic to be modified by sending control messages to a designated control port. The dynamic nature of the [*Dynamic Router*](DynamicRouter.html) can be combined with most forms of the [*Message Router*](MessageRouter.html). Chapter 3 introduced the concept of a [*Point-to-Point Channel*](PointToPointChannel.html) and a [*Publish-Subscribe Channel*](PublishSubscribeChannel.html). Sometimes, you need to send a message to more than one recipient, but want to maintain control over the recipients. The [*Recipient List*](RecipientList.html) allows you do just that. In essence, a [*Recipient List*](RecipientList.html) is a [*Content-Based Router*](ContentBasedRouter.html) that can route a single message to more than one destination channel. Some messages contain lists of individual items. How do you process these items individually? Use a [*Splitter*](Sequencer.html) to split the large message into individual messages. Each message can then be routed further and processed individually. However, you may need to recombine the messages that the [*Splitter*](Sequencer.html) created back into a single message. This is one of the functions an [*Aggregator*](Aggregator.html) performs. An [*Aggregator*](Aggregator.html) can receive a stream of messages, identify related messages and combine them into a single message. Unlike the other routing patterns, the [*Aggregator*](Aggregator.html) is a stateful [*Message Router*](MessageRouter.html) because it has to store messages internally until specific conditions are fulfilled. This mean that an [*Aggregator*](Aggregator.html) can consume a number of messages before it publishes a message. Because we use messaging to connect applications or components running on multiple computers, multiple messages can be processed in parallel. For example, more than one process may consume messages off a single channel. One of these processes may execute faster than another, causing messages to be processed out of order. However, some components depend on the correct sequence of individual messages, for example ledger-based systems. The [*Resequencer*](Resequencer.html) puts out-of-sequence messages back into sequence. The [*Resequencer*](Resequencer.html) is also a stateful [*Message Router*](MessageRouter.html) because it may need to store a number of messages internally until the message arrives that completes the sequence. Unlike the [*Aggregator*](Aggregator.html), though, the [*Resequencer*](Resequencer.html) ultimately publishes the same number of messages it consumed. The following table summarizes the properties of the [*Message Router*](MessageRouter.html) variants (we did not include the [*Dynamic Router*](DynamicRouter.html) as a separate alternative because any router can be implemented as a dynamic variant): | **Pattern** | **Number of Msgs Consumed** | **Number of Msgs Published** | **Stateful?** | **Comment** | | --- | --- | --- | --- | --- | | [*Content-Based Router*](ContentBasedRouter.html) | 1 | 1 | No (mostly) | | | [*Message Filter*](Filter.html) | 1 | 0 or 1 | No (mostly) | | | [*Recipient List*](RecipientList.html) | 1 | multiple (incl. 0) | No | | | [*Splitter*](Sequencer.html) | 1 | multiple | No | | | [*Aggregator*](Aggregator.html) | multiple | 1 | Yes | | | [*Resequencer*](Resequencer.html) | multiple | multiple | Yes | Publishes same number it consumes. | ## Composed Routers A key advantage of the [*Pipes and Filters*](PipesAndFilters.html) architecture is the fact that we can compose multiple filters into a larger solution. [*Composed Message Processor*](DistributionAggregate.html) or an [*Scatter-Gather*](BroadcastAggregate.html) combine multiple [*Message Router*](MessageRouter.html) variants to create more comprehensive solutions. Both patterns allow us to retrieve information from multiple sources and recombine it into a single message. While the [*Composed Message Processor*](DistributionAggregate.html) maintains control over the possible sources the [*Scatter-Gather*](BroadcastAggregate.html) uses a [*Publish-Subscribe Channel*](PublishSubscribeChannel.html) so that any interested component can participate in the process. Both the [*Composed Message Processor*](DistributionAggregate.html) and the [*Scatter-Gather*](BroadcastAggregate.html) route a single message to a number of participants concurrently and reassemble the replies into a single message. We can say that these patterns manage the *parallel routing* of a message. Two more patterns manage the *sequential routing* of a message, i.e. routing a message through a sequence of individual steps. If we want to control the path of a message from a central point we can use a [*Routing Slip*](RoutingTable.html) to specify the path the message should take. This pattern works just like the routing slip attached to office documents to pass them sequentially by a number of recipients. Alternatively, we can use a [*Process Manager*](ProcessManager.html) which gives us more flexibility but requires the message to return to a central component after each function. ## Architectural Patterns [*Message Router*](MessageRouter.html)s enable us to architect an integration solution using a central [*Message Broker*](MessageBroker.html). As opposed to the different message routing design patterns, this pattern describes a *hub-and-spoke* architectural style. ## The Right Router for the Right Purpose This chapter contains 10 patterns. How can we make it easy to find the right pattern for the right purpose? The following decision chart helps you find the right pattern for the right purpose by matter of simple yes/no decisions. For example, if you are looking for a simple routing pattern that consumes one message at a time but publishes multiple messages in sequential order, you should use a [*Splitter*](Sequencer.html). The diagram also helps illustrate how closely the individual patterns are related. For example, a [*Routing Slip*](RoutingTable.html) and a [*Process Manager*](ProcessManager.html) solve similar problems while a [*Message Filter*](Filter.html) does something rather different. ## Integration Pattern Language [Message Construct.](MessageConstructionIntro.html) [Message](Message.html) [Command Message](CommandMessage.html) [Document Message](DocumentMessage.html) [Event Message](EventMessage.html) [Request-Reply](RequestReply.html) [Return Address](ReturnAddress.html) [Correlation Identifier](CorrelationIdentifier.html) [Message Sequence](MessageSequence.html) [Message Expiration](MessageExpiration.html) [Format Indicator](FormatIndicator.html) [Message Routing](MessageRoutingIntro.html) [Pipes-and-Filters](PipesAndFilters.html) [Message Router](MessageRouter.html) [Content-based Router](ContentBasedRouter.html) [Message Filter](Filter.html) [Dynamic Router](DynamicRouter.html) [Recipient List](RecipientList.html) [Splitter](Sequencer.html) [Aggregator](Aggregator.html) [Resequencer](Resequencer.html) [Composed Msg. Processor](DistributionAggregate.html) [Scatter-Gather](BroadcastAggregate.html) [Routing Slip](RoutingTable.html) [Process Manager](ProcessManager.html) [Message Broker](MessageBroker.html) [Message Transformation](MessageTransformationIntro.html) [Message Translator](MessageTranslator.html) [Envelope Wrapper](EnvelopeWrapper.html) [Content Enricher](DataEnricher.html) [Content Filter](ContentFilter.html) [Claim Check](StoreInLibrary.html) [Normalizer](Normalizer.html) [Canonical Data Model](CanonicalDataModel.html) [Messaging Endpoints](MessagingEndpointsIntro.html) [Message Endpoint](MessageEndpoint.html) [Messaging Gateway](MessagingGateway.html) [Messaging Mapper](MessagingMapper.html) [Transactional Client](TransactionalClient.html) [Polling Consumer](PollingConsumer.html) [Event-driven Consumer](EventDrivenConsumer.html) [Competing Consumers](CompetingConsumers.html) [Message Dispatcher](MessageDispatcher.html) [Selective Consumer](MessageSelector.html) [Durable Subscriber](DurableSubscription.html) [Idempotent Receiver](IdempotentReceiver.html) [Service Activator](MessagingAdapter.html) [Messaging Channels](MessagingChannelsIntro.html) [Message Channel](MessageChannel.html) [Point-to-Point Channel](PointToPointChannel.html) [Publish-Subscr. Channel](PublishSubscribeChannel.html) [Datatype Channel](DatatypeChannel.html) [Invalid Message Channel](InvalidMessageChannel.html) [Dead Letter Channel](DeadLetterChannel.html) [Guaranteed Delivery](GuaranteedMessaging.html) [Channel Adapter](ChannelAdapter.html) [Messaging Bridge](MessagingBridge.html) [Message Bus](MessageBus.html) [Systems Mgmt.](SystemManagementIntro.html) [Control Bus](ControlBus.html) [Detour](Detour.html) [Wire Tap](WireTap.html) [Message History](MessageHistory.html) [Message Store](MessageStore.html) [Smart Proxy](SmartProxy.html) [Test Message](TestMessage.html) [Channel Purger](ChannelPurger.html)