This section explains, through an example scenario, how the Test Message EIP can be implemented using WSO2 ESB. The following topics are covered:
Introduction to Test Message
The Test Message EIP ensures the health of message processing components by preventing situations such as garbling outgoing messages due to an internal fault. For more information, refer to http://www.eaipatterns.com/TestMessage.html.
Figure 1: Test Message EIP
This example scenario demonstrates how to send a test message and determine the availability of a service. You can also see how the Scheduled Tasks in WSO2 ESB are used.
The diagram below depicts how to simulate the example scenario using the WSO2 ESB.
Figure 2: Example Scenario of the Test Message EIP
Before digging into implementation details, let's take a look at the relationship between the example scenario and the Detour EIP by comparing their core components.
|Test Message EIP (Figure 1)||Example Scenario of the Test Message EIP (Figure 2)|
|Application Messages||Simple Stock Quote Client|
|Test Data Generator||Test data generator role is played by the Task Scheduler in the ESB. It creates a message after a given interval and hands over the message to the main sequence.|
|Test Message Separator and Test Data Verifier||A Filter mediator inside |
- Download and install WSO2 ESB from http://wso2.com/products/enterprise-service-bus. For a list of prerequisites and step-by-step installation instructions, refer to Getting Started in the WSO2 ESB documentation.
- Start a sample Axis2 server instance on port 9000. For instructions, see ESB Samples Setup - Starting Sample Back-End Services 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
After setting this configuration, note that the Axis2 server is invoked every 25 seconds, and the following message on the WSO2 ESB console indicates that the test has passed.
If you stop the Axis2 server, you will get the following message indicating that the test has failed.
How the implementation works
Let's investigate the elements of the ESB configuration in detail. The line numbers below refer to the ESB configuration shown above.
- sequence [line 8 in ESB config] - The sequence with key
sendSeqdefines the endpoint where messages will be sent and defines the sequence (receiveSeq) that will receive responses.
- fault sequence [line 17 in ESB config] - The fault sequence provides a channel for handling faults.
- filter [line 29 in ESB config] - A filter mediator is used within the fault sequence to determine whether the symbol property of the message passing through this filter contains
TEST. If it does, it will be logged, and no fault message is passed onto the requesting client. If
TESTdoes not exist, a fault message is passed as usual.
- sequence [line 68 in ESB config] - This is the main sequence invoked by default when a request is made to the ESB. This sequence calls the
sendSeqsequence (line 8 in ESB config).
- task [line 78 in ESB config] - A task in the ESB runs periodically based on a given timer. This timer is specified using the trigger element. In this case, the task is set to run every 25 seconds. This task uses the Synapse
MessageInjectorclass to inject a message into the Synapse environment.
- property [line 85 in ESB config] - This property, defined inside the task, specifies the message body.
- property [line 92 in ESB config] - This property, defined inside the task, sets the SOAP Action to
- property [line 95 in ESB config] - This property, defined inside the task, specifies the address where the message generated by the task is sent.