--- url: "http://www.enterpriseintegrationpatterns.com/ContentBasedRouter.html" titulek: "Content-Based Router - Enterprise Integration Patterns" h1: "" popis: "How do we handle a situation where the implementation of a single logical function (e.g., inventory check) is spread across multiple physical systems?" jazyk: "en" kanonicka: "" drobecky: [] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-15 15:34:13" znaku: 5605 slov: 511 kodovani: "utf-8" sha256: "2e1bcb059062a373d4a86319925c989b73ec891cebffe089608b4e48bc69256c" --- | | Content-Based Router[Messaging Patterns](index.html) » [Message Routing](MessageRoutingIntro.html) | [Contents](toc.html)[⇐ Prev](MessageRoutingIntro.html)[Next ⇒](Filter.html) | | --- | --- | --- | Assume that we are building an order processing system. When an incoming order is received, we first validate the order and then verify that the ordered item is available in the warehouse. This function is performed by the inventory system. This sequence of processing steps is a perfect candidate for the [*Pipes and Filters*](PipesAndFilters.html) style. We create two filters, one for the validation step and one for the inventory system, and route the incoming messages through both filters. However, in many enterprise integration scenarios more than one inventory system exists with each system being able to handle only specific items. How do we handle a situation where the implementation of a single logical function (e.g., inventory check) is spread across multiple physical systems? Use a *Content-Based Router* to route each message to the correct recipient based on message content. The *Content-Based Router* examines the message content and routes the message onto a different channel based on data contained in the message. The routing can be based on a number of criteria such as existence of fields, specific field values etc. When implementing a *Content-Based Router*, special caution should be taken to make the routing function easy to maintain as the router can become a point of frequent maintenance. In more sophisticated integration scenarios, the *Content-Based Router* can take on the form of a configurable rules engine that computes the destination channel based on a set of configurable rules. ... Read the entire pattern in the book [Enterprise Integration Patterns](/books1.html) ## Example: Apache Camel[NEW](/ramblings/eip1_examples_updated.html) Many open source ESBs like [Apache Camel](http://camel.apache.org/) have direct support for many Enterprise Integration Patterns, wither in a Java-based DSL or as configuration. For example, setting up a *Content-Based Router* in Camel is quite easy and idiomatic by using a RouteBuilder: ``` RouteBuilder builder = new RouteBuilder() { public void configure() { errorHandler(deadLetterChannel("mock:error")); from("direct:in") .choice() .when(header("type").isEqualTo("widget")) .to("direct:widget") .when(header("type").isEqualTo("gadget")) .to("direct:gadget") .otherwise() .to("direct:other"); } }; ``` **Related patterns:** [*Dynamic Router*](DynamicRouter.html), [*Message Filter*](Filter.html), [*Invalid Message Channel*](InvalidMessageChannel.html), [*Message Router*](MessageRouter.html), [*Pipes and Filters*](PipesAndFilters.html), [*Publish-Subscribe Channel*](PublishSubscribeChannel.html), [*Routing Slip*](RoutingTable.html), [*Transactional Client*](TransactionalClient.html) --- ## 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)