This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, go to https://wso2.com/documentation/.
Event Message
This section explains, through an example scenario, how the Event Message EIP can be implemented using the WSO2 ESB. The following topics are covered:
Introduction to Event Message
The Event Message EIP is used for reliable, asynchronous event notification between applications. For more information, see http://www.eaipatterns.com/EventMessage.html.
Figure 1: Event Message EIP
Example scenario
When a subject has an event to be announced, it will create an event object, wrap it in a message, and send it to a set of subscribers. This example scenario uses several Axis2 server instances as subscribers. When a message arrives in the ESB, it will be transmitted through the event mediator to each of these server instances that act as a subscriber.
The following diagram depicts how this example can be simulated using the ESB.
Figure 2: Example scenario of the Event Message EIP
Before digging into implementation details, let's take a look at the relationship between the example scenario and the Event Message EIP, by comparing their core components.
Event Message EIP (Figure 1) | Event Message Example Scenario (Figure 2) |
---|---|
Subject | Stock Quote Client |
Event Message | Event, Topic |
Observer | Stock Quote Service |
The ESB configuration
Given below is the ESB configuration for simulating the example scenario explained above.
<?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://ws.apache.org/ns/synapse"> <proxy name="EventMessageProxy" transports="https http" startOnLoad="true" trace="disable"> <target> <inSequence> <event topic="stockquote" /> </inSequence> <outSequence> <send /> </outSequence> </target> </proxy> </definitions>
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
Event-Message_1.0.0.zip
file, 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 need to start two instances of the back-end service (Stock Quote Service) to simulate this example.
- Follow the steps below to create an event for the subscriber with port 9000.
- Start the ESB and log into its Management Console. For instructions, see Starting the ESB in WSO2 ESB documentation.
- Click Topics from the Main menu, and then click Add.
- Enter
stockquote
as the topic name and then click Add Topic. - In the Topic browser, click the newly created
stockquote
topic and then click Subscribe to create a static subscription. - Enter
http://localhost:9000/services/SimpleStockQuoteService
in the Event Sink URL field and click Subscribe.
- Repeat the above steps to add another subscriber in port 9001.
Executing the sample
Send the following message from a SOAP client like SoapUI:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd"> <soapenv:Header/> <soapenv:Body> <ser:getQuote> <ser:request> <xsd:symbol>foo</xsd:symbol> </ser:request> </ser:getQuote> </soapenv:Body> </soapenv:Envelope>
Analyzing the output
Observe the two Axis2 server instances. Both instances will receive the request, which was sent from the client.
Ouput of both Axis Server consoles:
samples.services.SimpleStockQuoteService :: Generating quote for : foo
You don't get a response in the Soap Ui.