This section explains, through an example scenario, how the Point-to-Point Channel EIP can be implemented using the WSO2 ESB. The following topics are covered:
Introduction to Point-to-Point Channel
The Point-to-Point Channel EIP ensures that only a single receiver consumes a message (when there are multiple receivers waiting to consume the message). For more information, see Point to Point Channel.
Figure 1: Point-to-Point Channel EIP
The following diagram depicts an example scenario that is carried out using the ESB. As shown below, there are three instances of the Stock Quote service connected to the ESB as consumers. The client application requests a stock quote from the stock inventory service (Stock Quote service). The ESB receives the messages sent from the client and routes each message to a single consumer (single Stock Quote service instance) at a time.
Figure 2: Example scenario of the Point-to-Point Channel EIP
Before digging into implementation details, let's take a look at the relationship between the example scenario and the Point-to-Point Channel EIP by comparing their core components.
|Point-to-Point EIP (Figure 1)||Point-to-Point Channel Example Scenario (Figure 2)|
|Stock Quote Client|
|Stock Quote Requests|
Point to Point Channel
|Receiver||Three instances of the 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>.
- <send> - When a matching case is found, the Send mediator routes the message to the endpoint indicated by the address URI.
- <load balance> - Manages the array of services defined within this endpoint. It streams the request only to one instance, which is selected using the given algorithm.
- <outSequence> - Receives the response from an endpoint and sends the response back to the client.
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
Point-To-Point_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 three instances of the back-end service (Stock Quote Service) to simulate this example.
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 should be as follows:
Analyzing the output
When you send the request, the ESB first receives the message and then routes it to the back-end service. Out of the three instances of the back-end service, only one service consumes this single message.
The following output will be printed on the console of the Axi2 server that received the message. This confirms that the request is successfully received by the back-end service.
The generated stock quote will then be sent to the client application (Stock Quote Client). The following output will be printed on the client application's console:
If you try sending multiple messages, the ESB will route the messages to each of the back-end services in a Round Robin pattern. You can verify this by checking the console logs of each of the Axis2 servers.