Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The Point-to-Point Channel EIP pattern 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

Example scenario

The example scenario uses an inventory of stocks. It illustrates how a stock quote is generated, which only a single consumer receives at a given time. The diagram below depicts how this example is simulated using the ESBfollowing 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

...

Code Block
<definitions xmlns="http://ws.apache.org/ns/synapse">
   <proxy xmlns="http://ws.apache.org/ns/synapse" name="PointToPointProxy" transports="http https" startOnLoad="true" >
       <target>
           <inSequence>
               <send>
                   <endpoint>
                       <!-- Channel With Multiple Endpoints Load Balancer Will Ensure that only one will receive it -->
                       <loadbalance>
                           <endpoint>
                               <address uri="http://localhost:9000/services/SimpleStockQuoteService/" />
                           </endpoint>
                           <endpoint>
                               <address uri="http://localhost:9001/services/SimpleStockQuoteService/" />
                           </endpoint>
                           <endpoint>
                               <address uri="http://localhost:9002/services/SimpleStockQuoteService/" />
                           </endpoint>
                       </loadbalance>
                   </endpoint>
               </send>
           </inSequence>
           <outSequence>
               <respond/>
           </outSequence>
       </target>
   </proxy>
</definitions>  definitions>

The configuration elements

...

You need to set up the ESB, and the back-end service:

  1. Download the Point-To-Point_1.0.0.zip file, which includes the ESB configuration described above. 
  2. See Setting up the Environment for instructions on setting up the ESB and the back-end service.

    Info

    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.

  1. Open a new terminal, and navigate to the <ESB_HOME>/samples/axis2Client/ directory. The Stock Quote client application is stored in this directory.
  2. Execute the following command to send the request to the ESB.

    Code Block
    ant stockquote -Dtrpurl=http://localhost:8280/services/point-to-point-proxy -Dsymbol=foo

    The structure of the request should be as follows:

    Code Block
    <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>
                 <ser:symbol>foo</ser:symbol>
             </ser:request>      
          </ser:getQuote>
       </soapenv:Body>
    </soapenv:Envelope>

Analyzing the output

Note that, out of all three instances of the Stock Quote service (Axis2 server), only one server acquires the sent request at a given time.

Stock client response: 

Standard :: Stock price = $81.06211284751495

Service console response:

samples.services.SimpleStockQuoteService :: Generating quote for : foo

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.

Code Block
samples.services.SimpleStockQuoteService :: Generating quote for : foo

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: 

Code Block
Standard :: Stock price = $81.06211284751495
Info

If you try sending multiple requestsmessages, you will notice in the Console 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 server instances that the three of them are receiving the message one after another (i.e., in Round Robin pattern)servers.