This section explains, through an example scenario, how the Pipes and Filters EIP can be implemented using the WSO2 ESB. The following topics are covered:
Introduction to Pipes and Filters
The Pipes and Filters EIP breaks down a large task into smaller subsets of independent steps that are chained together. This is useful when a sequence of processing steps are required to perform a single event in an integration scenario. The main use case of this EIP is to maintain independence and flexibility between each processing step.
For more information, go to Pipes and Filters.
Figure 1: Pipes and Filters EIP
The following diagram depicts an example scenario, where a stock quote request is sent from a client to a service (Stock Quote Service). The request is first received by the ESB, which transmits the request through the following filters:
- Check Username filter: To verify the username.
- Check User ID filter: To verify the user ID.
Once the request successfully passes through the filters (i.e., the filtering criteria is fulfilled), the ESB sends the stock quote request to the back-end service (Stock Quote Service) for processing.
Figure 2: Example scenario of the Pipes and Filters EIP
Before digging into implementation details, let's take a look at the relationship between the example scenario and the Pipes and Filters EIP by comparing their core components.
|Pipes and Filters EIP (Figure 1)||Example Scenario of the EIP (Figure 2)|
|Stock Quote Request|
|We useto verify the validity of the message (checking the user name and user ID). If the message meets the criteria of the first filter, we forward it to the next filter, and then to the stock quote service.|
|Clean Order||Stock Quote Service|
The ESB configuration
Given below is the ESB configuration for simulating the example scenario explained above.
The configuration elements
The elements used in the above ESB configuration are explained below.
- <proxy> - This is the proxy service that should be invoked to execute the configuration.
- <inSequence> - A message is first received by the proxy service, and then directed to this sequence.
- <outSequence> - This sequence is triggered after the execution of the <inSequence>.
- <sequence> - This is an external sequence, which is invoked by the proxy.
- <filter mediator> - This mediator filters an incoming message based on the constraints specified in the
- <then> - Actions to take if the conditions are satisfied through the filtering criteria.
- <else> - Actions to take if the conditions are not satisfied.
Simulating the example scenario
Now, let's try out the example scenario explained above.
Setting up the environment
You need to set up the ESB, and the back-end service:
- Download the
Pipes-and-Filters.zipfile, which includes the ESB configuration described above.
See Setting up the Environment for instructions on setting up the ESB and the back-end service.
When you set up the environment, note that you only need to start one instance of the back-end service (Stock Quote Service) to simulate this example.
Executing the sample
Send the following request to the ESB, by using a SOAP client. When you send the request, you will need the wsdl URL of the proxy service defined in the ESB configuration. The default wsdl URL for this proxy service is http://localhost:8280/services/pipes-and-filters-proxy?wsdl.
Analyzing the result
When you send the request, the ESB first receives the message and then routes it to the back-end service (StockQuoteService). The following output will be printed on the Axis2 server's console, confirming that the request is successfully received by the back-end service.
You can view the response in the SOAP UI as follows. If you send another request by changing the name or ID, you can see how the request fails.