This section explains, through an example scenario, how the Message Filter EIP can be implemented using WSO2 ESB. The following topics are covered:
Introduction to Message Filter
The Message Filter EIP checks an incoming message against a certain criteria that the message should adhere to. If the criteria is not met, the filter will discard the message. Otherwise, it will route the message to the output channel. For more information, refer to http://www.eaipatterns.com/Filter.html.
Figure 1: Message Filter EIP
The example scenario depicts an inventory for stocks where an incoming request will be filtered based on its content. If the content meets the criteria, the message filter will allow the request to proceed. Otherwise, the message will be dropped.
The diagram below depicts how to simulate the example scenario using WSO2 ESB.
Scenario 1: content meeting the filter criteria
Scenario 2: content not meeting the filter criteria
Figure 2: Message Filter Example Scenario
Before digging into implementation details, let's take a look at the co-relation of the example scenario and the Message Filter EIP by comparing their core components.
|Message Filter EIP (Figure 1)||Message Filter Example Scenario (Figure 2)|
|Quote||Stock Quote Request|
|Message Filter||Filter Mediator is used to filter the content of the incoming message|
- Download and install WSO2 ESB from http://wso2.com/products/enterprise-service-bus. For a list of prerequisites and step-by-step installation instructions, see Installation Guide in the WSO2 ESB documentation.
- Start a sample Axis2 server instance on port 9000. For instructions, see Setting up the ESB Samples - Starting the Axis2 server in the WSO2 ESB documentation.
Start the ESB server and log into its management console UI (
//). In the management console, navigate to the Main menu and click Source View in the Service Bus section. Next, copy and paste the following configuration, which helps you explore the example scenario, to the source view.
Simulating the sample scenario
- Send a request using the Stock Quote client to WSO2 ESB in the following manner. For information about the Stock Quote client, see Sample Clients in the WSO2 ESB Documentation.
ant stockquote -Dtrpurl=-Dsymbol=foo
- After executing the above command through the client, observe that the request is transferred to the foo inventory service and a response is received. If the
-Dsymbolparameter was changed to another value, there will be no response.
The structure of the request is as follows:
How the implementation works
Let's investigate the elements of the ESB configuration in detail. The line numbers below are mapped with the ESB configuration shown above.
Proxy Service - The proxy service takes requests and forwards them to appropriate the back-end service, abstracting the routing logic from the client. Regardless of the request, the client sends it to the exposed service and not to the back-end services.
inSequence - When the service is invoked through the client, the message will be processed by the inSequence and sent as per the routing logic.
filter - Filters incoming messages, dropping any that do not meet the criteria.
send - When a matching case is found, the send mediator will route the message to the endpoint specified in address URI.
outSequence - The response from the endpoint is processed by the outSequence. The message will be transferred back to the sender.