| <?xml version="1.0" encoding="ISO-8859-1" ?> |
| <!-- |
| ~ Licensed to the Apache Software Foundation (ASF) under one |
| ~ or more contributor license agreements. See the NOTICE file |
| ~ distributed with this work for additional information |
| ~ regarding copyright ownership. The ASF licenses this file |
| ~ to you under the Apache License, Version 2.0 (the |
| ~ "License"); you may not use this file except in compliance |
| ~ with the License. You may obtain a copy of the License at |
| ~ |
| ~ http://www.apache.org/licenses/LICENSE-2.0 |
| ~ |
| ~ Unless required by applicable law or agreed to in writing, |
| ~ software distributed under the License is distributed on an |
| ~ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| ~ KIND, either express or implied. See the License for the |
| ~ specific language governing permissions and limitations |
| ~ under the License. |
| --> |
| |
| <document> |
| <properties> |
| <title>Apache Synapse - Sample 101</title> |
| </properties> |
| <body> |
| <section name="Sample 101: Using WS-ReliableMessaging for Outgoing Messages"> |
| <div class="xmlConf"><definitions xmlns="http://ws.apache.org/ns/synapse"> |
| |
| <sequence name="main"> |
| <in> |
| <RMSequence single="true" version="1.0"/> |
| <send> |
| <endpoint name="reliable"> |
| <address uri="http://localhost:9000/services/ReliableStockQuoteService"> |
| <enableRM/> |
| <enableAddressing/> |
| </address> |
| </endpoint> |
| </send> |
| </in> |
| <out> |
| <send/> |
| </out> |
| </sequence> |
| |
| </definitions></div> |
| <subsection name="Objective"> |
| <p> |
| Demonstrate the ability of Synapse to exchange messages with an endpoint |
| reliably, using WS-ReliableMessaging |
| </p> |
| </subsection> |
| <subsection name="Pre-requisites"> |
| <p> |
| <ul> |
| <li> |
| Deploy the ReliableStockQuoteService in the sample Axis2 server and start Axis2 |
| </li> |
| <li> |
| Start Synapse using the configuration numbered 101 (repository/conf/sample/synapse_sample_101.xml) |
| <div class="command"> |
| Unix/Linux: sh synapse.sh -sample 101<br/> |
| Windows: synapse.bat -sample 101 |
| </div> |
| </li> |
| </ul> |
| </p> |
| </subsection> |
| <subsection name="Executing the Client"> |
| <p> |
| In the above configuration, WS-RM is engaged on the endpoint using the |
| <enableRM/> tag. It is possible to engage WS-RM to both Address and WSDL |
| endpoints using this tag. In addition to the RM enabled endpoint, RMSequence |
| mediator is specified before the send mediator. This mediator is used to specify |
| the set of messages to be sent using a single RM sequence. In this sample it is |
| specified as single message per sequence. It also specifies the version of the |
| WS-RM to be used. Refer to the Synapse configuration language documentation for |
| more information about the RMSequence mediator. RM related SOAP headers are |
| removed form the message in the out mediator as WS-RM message exchange takes |
| place only between the Synapse and the server. Now run the sample client using |
| the following command. |
| </p> |
| <div class="command">ant stockquote -Dsymbol=IBM -Dmode=quote -Daddurl=http://localhost:8280</div> |
| <p> |
| You can observe the client output displaying the quote price for IBM as follows: |
| </p> |
| <div class="consoleOutput">Standard :: Stock price = $95.26454380258552</div> |
| <p> |
| There is no difference to be observed between the normal message exchange and |
| WS-RM enabled message exchange as far as client and server outputs are considered. |
| But if you look at the wire level messages, you would observe additional WS-RM |
| messages and WS-RM headers. Synapse, the initiator of the RM sequence, first try |
| to create a sequence by sending a message with CreateSequence element. |
| </p> |
| <div class="consoleOutput">... |
| <soapenv:Body> |
| <wsrm:CreateSequence xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm"> |
| <wsrm:AcksTo> |
| <wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address> |
| </wsrm:AcksTo> |
| <wsrm:Offer> |
| <wsrm:Identifier>urn:uuid:546F6F33FB7D8BBE351179807372769</wsrm:Identifier> |
| </wsrm:Offer> |
| </wsrm:CreateSequence> |
| </soapenv:Body> |
| ...</div> |
| <p> |
| Sample Axis2 server responds to CreateSequence request with the following |
| message: |
| </p> |
| <div class="consoleOutput">... |
| <soapenv:Body> |
| <wsrm:CreateSequenceResponse xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm"> |
| <wsrm:Identifier>urn:uuid:879853A6871A66641C1179807373270</wsrm:Identifier> |
| <wsrm:Accept> |
| <wsrm:AcksTo> |
| <wsa:Address>http://localhost:9000/services/ReliableStockQuoteService</wsa:Address> |
| </wsrm:AcksTo> |
| </wsrm:Accept> |
| </wsrm:CreateSequenceResponse> |
| </soapenv:Body> |
| ...</div> |
| <p> |
| Once the sequence is established, Synapse sends the request to the server with |
| the pre-negotiated sequence ID. |
| </p> |
| <div class="consoleOutput"><soapenv:Envelope xmlns:wsa="http://www.w3.org/2005/08/addressing" |
| xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> |
| <soapenv:Header> |
| <wsa:To>http://localhost:9000/services/ReliableStockQuoteService</wsa:To> |
| <wsa:MessageID>urn:uuid:DB9A5257B637DDA38B1179807372560712002-1515891720</wsa:MessageID> |
| <wsa:Action>urn:getQuote</wsa:Action> |
| <wsrm:Sequence xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm" |
| soapenv:mustUnderstand="1"> |
| <wsrm:Identifier>urn:uuid:879853A6871A66641C1179807373270</wsrm:Identifier> |
| <wsrm:MessageNumber>1</wsrm:MessageNumber> |
| <wsrm:LastMessage/> |
| </wsrm:Sequence> |
| </soapenv:Header> |
| <soapenv:Body> |
| <m0:getQuote xmlns:m0="http://services.samples"> |
| <m0:request> |
| <m0:symbol>IBM</m0:symbol> |
| </m0:request> |
| </m0:getQuote> |
| </soapenv:Body> |
| </soapenv:Envelope></div> |
| <p> |
| Synapse keeps on sending the above message till the server responds with a valid |
| response message with 200 OK HTTP header. If the server is not ready with a |
| response, it will respond with 202 Accepted HTTP header for all requests. Once |
| the server is ready with a response it will send the response message with |
| sequence ID as follows. |
| </p> |
| <div class="consoleOutput"><soapenv:Envelope xmlns:wsa="http://www.w3.org/2005/08/addressing" |
| xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> |
| <soapenv:Header> |
| <wsa:MessageID>urn:uuid:879853A6871A66641C1179807373804</wsa:MessageID> |
| <wsa:Action>http://services.samples/ReliableStockQuoteServicePortType/getQuoteResponse |
| </wsa:Action> |
| <wsa:RelatesTo>urn:uuid:DB9A5257B637DDA38B1179807372560712002-1515891720</wsa:RelatesTo> |
| <wsrm:Sequence xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm" |
| soapenv:mustUnderstand="1"> |
| <wsrm:Identifier>urn:uuid:546F6F33FB7D8BBE351179807372769</wsrm:Identifier> |
| <wsrm:MessageNumber>1</wsrm:MessageNumber> |
| <wsrm:LastMessage/> |
| </wsrm:Sequence> |
| <wsrm:SequenceAcknowledgement xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm" |
| soapenv:mustUnderstand="1"> |
| <wsrm:Identifier>urn:uuid:879853A6871A66641C1179807373270</wsrm:Identifier> |
| <wsrm:AcknowledgementRange Lower="1" Upper="1"/> |
| </wsrm:SequenceAcknowledgement> |
| </soapenv:Header> |
| <soapenv:Body> |
| <ns:getQuoteResponse xmlns:ns="http://services.samples/xsd"> |
| ...</div> |
| <p> |
| Now both Synapse and the server are done with the actual message exchange. Then |
| Synapse sends a request to terminate the sequence as follows: |
| </p> |
| <div class="consoleOutput"><soapenv:Envelope xmlns:wsa="http://www.w3.org/2005/08/addressing" |
| xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> |
| <soapenv:Header> |
| <wsa:To>http://localhost:9000/services/ReliableStockQuoteService</wsa:To> |
| <wsa:MessageID>urn:uuid:546F6F33FB7D8BBE351179807379591</wsa:MessageID> |
| <wsa:Action>http://schemas.xmlsoap.org/ws/2005/02/rm/TerminateSequence</wsa:Action> |
| <wsrm:SequenceAcknowledgement xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm" |
| soapenv:mustUnderstand="1"> |
| <wsrm:Identifier>urn:uuid:546F6F33FB7D8BBE351179807372769</wsrm:Identifier> |
| <wsrm:AcknowledgementRange Lower="1" Upper="1"/> |
| </wsrm:SequenceAcknowledgement> |
| </soapenv:Header> |
| <soapenv:Body> |
| <wsrm:TerminateSequence xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm"> |
| <wsrm:Identifier>urn:uuid:879853A6871A66641C1179807373270</wsrm:Identifier> |
| </wsrm:TerminateSequence> |
| </soapenv:Body> |
| </soapenv:Envelope></div> |
| <p> |
| Server responds to the sequence termination message, accepting to terminate the |
| sequence as follows. |
| </p> |
| <div class="consoleOutput"><soapenv:Envelope xmlns:wsa="http://www.w3.org/2005/08/addressing" |
| xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> |
| <soapenv:Header> |
| <wsa:ReplyTo> |
| <wsa:Address>http://localhost:9000/services/ReliableStockQuoteService</wsa:Address> |
| </wsa:ReplyTo> |
| <wsa:MessageID>urn:uuid:879853A6871A66641C1179807380190</wsa:MessageID> |
| <wsa:Action>http://schemas.xmlsoap.org/ws/2005/02/rm/TerminateSequence</wsa:Action> |
| </soapenv:Header> |
| <soapenv:Body> |
| <wsrm:TerminateSequence xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm"> |
| <wsrm:Identifier>urn:uuid:546F6F33FB7D8BBE351179807372769</wsrm:Identifier> |
| </wsrm:TerminateSequence> |
| </soapenv:Body> |
| </soapenv:Envelope></div> |
| <p> |
| Note that although each of above messages are separate SOAP messages, in most |
| cases they will be exchanged in a single socket connection as HTTP Keep-Alive |
| header is being used. |
| </p> |
| |
| </subsection> |
| </section> |
| <p><a href="../samples.html">Back to Catalog</a></p> |
| </body> |
| </document> |