11.2. Introducing Content-Based Routing with ESB

Normally, data in the Enterprise Service Bus is packaged, transferred and stored in the form of a message. Messages are addressed to endpoint references (which point to either services or clients.) An endpoint reference's role is to identify the machine or process or object that will ultimately deal with the content of the message. However, what happens if the specified address is no longer valid? Situations that may lead to this scenario include those in which the service has failed or been removed.
It is also possible that the service no longer deals with messages of that particular type, in which case presumably some other service will still deal with the original function, but that still leaves the question of "How should the message be handled?" What if other services besides that which is the intended recipient are interested in the message's contents? What if no destination is specified?
This is where content-based routing comes in. The way that content-based routing works, a message is routed by being opened and then having a set of rules applied to its content. These rules are used to ascertain which parties are interested in it, allowing the ESB to determine the destination where it should be sent. This relieves the sending application of the need to know where the message should go.
Content-based routing systems are built around two components: routers (of which there may be only one) and services (of which there are normally more than one). Services are the components that ultimately "consume" the messages. The way in which each service indicates its interest in specific types of messages to the router is implementation-dependent, but some mapping must exist between the message type (or some other aspect of the message content) and the services in order for the router to direct them appropriately.
Routers, as their name suggests, "route" messages. They examine the content of messages as they receive them, apply rules to that content and then forward the messages as the rules dictate.
In addition to routers and services, some systems also include harvesters. The role of these tools is find interesting information, package it in the guise of a formatted message and send it to a router. Harvesters "mine" many sources of information, including mail transfer agent message stores, news servers, databases and other legacy systems.