The Message Router EIP reads the content of a message and routes it to a specific recipient based on its content. When the implementation of a specific logical function is distributed across multiple physical systems, an incoming request needs to be passed on to the correct service based on the content of the request. A Message Router is useful in handling such scenarios.
The Message Router performs a logical function (such as an inventory check). It receives a request message (new order), reads it, and routes the request to one of the two recipients according to the content of the message. The router is also defined as a special type of a filter.
For more information, go to Message Router.
The following sections explain how you can implement a sample scenario of this EIP using the ESB profile of WSO2 EI.
Sample scenario
The sample scenario depicts an inventory for stocks, and how Message Router EIP routes a message to a different service based on the content of the message. When the router receives a stock request, it reads the content of the request as follows.
- If the request is made to foo, it is routed to fooOutQueue.
- If the request is for bar, it is routed to barOutQueue.
The Switch and Send mediators of the ESB profile of WSO2 EI simulate the Message Router EIP. The Switch Mediator depicts the Router and observes the content of the message, while the Send Mediator sends the message to a selected recipient.
Each case defined in the Switch mediator is used to decide the routing of the message to the appropriate service. fooOutQueue and barOutQueue act as two separate services.
Simulating the sample scenario
Follow the below instructions to simulate this sample scenario.
Analyzing the output
After you execute the above command through the client, observe that the request is transferred to foo inventory service
. Notice the following processed server log in the Stock Quote
Client console:
Standard :: Stock price = $77.86763451813164
Change the -Dsymbol
parameter to bar
and run the folloiwng command:
ant stockquote -Dtrpurl=http://localhost:8280/services/message-router-proxy
-Dsymbol=bar
Now, the request goes to bar inventory service
. Notice the following processed server log in the Stock Quote
Client console:
Standard :: Stock price = $64.81823486260222