Sample 1: Simple Content-Based Routing (CBR) of Messages
 Objective: Introduction to simple content-based routing shows how a message could be made to pass through ESB using the Dumb Client mode, where ESB acts as a gateway to accept all messages and then performs mediation and routing based on message properties or content.
<definitions xmlns="http://ws.apache.org/ns/synapse"> <sequence name="main"> <in> <!-- filtering of messages with XPath and regex matches --> <filter source="get-property('To')" regex=".*/StockQuote.*"> <send> <endpoint> <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> </endpoint> </send> <drop/> </filter> <send/> </in> <out> <send/> </out> </sequence> </definitions>
Prerequisites:
- Start the Synapse configuration numbered 1:
wso2esb-samples.sh -sn 1
- Start the Axis2 server and deploy the
SimpleStockQuoteService
if not already deployed.
Execute the Dumb Client as:
ant stockquote -Dtrpurl=http://localhost:8280/services/StockQuote
This time you will see ESB receiving a message for which ESB was set as the ultimate receiver of the message. ESB performs a match to the path/StockQuoteand
based on the To
EPR of the following location:
As the request matches the XPath expression of the Filter Mediator, the Filter Mediator's child mediators execute. It sends the message to a different endpoint as specified by the endpoint definition. The Drop Mediator terminates further processing of the current message in a configuration. During response processing, the filter condition fails and thus the implicit Send Mediator forwards the response back to the client.