This section explains, through an example scenario, how the Publish-Subscribe Channel EIP can be implemented using the WSO2 ESB. The following topics are covered:
Introduction to Publish-Subscribe Channel
The Publish-Subscribe Channel EIP receives messages from the input channel, and then splits and transmits them among its subscribers through the output channel. Each subscriber has only one output channel. For more information, go to Publish-Subscribe Channel.
Figure 1: Publisher-Subscribe Channel EIP
The following diagram depicts an example scenario, where the Publish-Subscribe Channel EIP is implemented using the ESB. In this example, a stock inventory is exposed through two instances of the Stock Quote Service. When a client sends a message, the ESB receives the message and routes it both instances of the back-end service (Stock Quote service). Both back-end services are subscribed to the ESB through the event mediator.
Figure 2: Example scenario of the Publish-Subscribe Channel EIP
Before digging into implementation details, let's take a look at the relationship between the example scenario and the Publish-Subscribe Channel EIP by comparing their core components.
|Publish-Subscribe Chanel EIP (Figure 1)||Publish-Subscribe Channel Example Scenario (Figure 2)|
|Stock Quote Request|
|Stock Quote service instance|
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.
- <main sequence> - The default sequence that gets triggered when the user invokes the ESB.
- <event> - Allows you to define a set of receivers.
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
Publish-Subscribe_1.0.0.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 need to start two instances of the back-end service (Stock Quote Service) to simulate this example.
Your ESB, as well as the two back-end services, should not be started.
Now, you can log in to the ESB's management console and create an event as explained below.
Log in to the management console.
Click Topics on the Main menu, and then click Add.
PublisherSubsciberas the topic name, and click Add Topic to create the topic. You will be directed to the Topic Browser tree view where the new topic is displayed.
Click the new topic (in the Topic Browser), and click Subscribe to create a static subscription.
as the Event Sink URL, and click Subscribe. The first back-end service (Stock Quote service) that was started on port 9000 of the Axis2 server is now subscribed to the ESB topic.
Click the new topic (in the Topic Browser) again, and click Subscribe to create another static subscription.
- Enter http://localhost:9001/services/SimpleStockQuoteService as the Event Sink URL (note that the port is changed to 9001), and click Subscribe. The second back-end service (Stock Quote service) that was started on port 9001 of the Axis2 server is now subscribed to the ESB topic.
- If you click the topic (in the Topic Browser) again and click Details, you can see the two subscriptions listed as shown below.
Executing the sample
Let's send a request to the ESB using the Stock Quote Client application. Find out more about the Stock Quote Client from the ESB documentation.
- Open a new terminal, and navigate to the
<ESB_HOME>/samples/axis2Client/directory. The Stock Quote client application is stored in this directory.
Execute the following command to send the request to the ESB.
The structure of the request is as follows:
Analyzing the output
When you execute the command above, the ESB first receives the message and then routes it to the two back-end services (StockQuoteService), simultaneously. The following output will be printed on the consoles of both Axis2 servers.
Note that the Stock Quote client application does not receive a response.