Web-Service Reliable Messaging (WS-ReliableMessaging) is a standard which describes a protocol on how to deliver messages reliably between distributed applications. Message failures due to software component, system, network failures can be overcome though this protocol. This protocol describes a transport-independent protocol, such that messages can be exchanged between systems. For further information, please go through the WS-RM specification  which completely describes about this topic. For WSO2 ESB, WS-RM is not a novel concept, as it has been there in previous releases. But with new release, WSO2 ESB 4.9.0, WSO2 has separated QoS from fresh pack. Instead, you can installed WS-RM as a feature from p2-repo. Another major changes are that, now WS-RM operates on top of CXF WS-RM  , and acting as an inbound endpoint .
In this post, I’m not going into comprehensively describe on WS-RM, but going to show how that can be configured in ESB. If you need to read more on WS-RM protocol, I recommend to access WS-RM specification , which is a good source for that. Now, let’s move on step-by-step with a sample use-case.
First you need to understand that, WS-RM inbound is designed to reliably exchange message between client and WSO2 ESB. So, the message flow diagram can be shown as follows:
For this example, I’m using SimpleStockQuote service which comes with WSO2 ESB. You can read more on configuring and starting the service on default port from the documentation. If you have properly configured it, you should be able to access its wsdl via “http://localhost:9000/services/SimpleStockQuoteService?wsdl“.
Next, you need to install “CXF WS Reliable Messaging” feature from p2-repo. About installing features please go through the documentation Installing Features. With this step, you have completed setting up the infrastructure for use-case. Also please note that, this feature requires cxf-bundle, and jetty-bundle. Make-sure, you have no conflicts regarding installation of those bundles.
In order to configure CXF server, we need to give a configuration file. Sample configuration can be also found at CXF Inbound Endpoint Documentation. In that configuration file, you may need to configure the paths to key stores. A sample can be found at . For this sample, configure it’s key store paths and place it in “<ESB_HOME>/repository/conf/cxf” folder.
Now, I’m going to create a new WS-RM inbound endpoint. For that select “Inbound Endpoints” from left panel. Then click “Add Inbound Endpoint“. Then you’ll get a page to initiate an inbound endpoint. At this stage you need to give a name to WS-RM inbound endpoint, and select type as “Custom“. You have to do that because, I have initially mentioned that WS-RM does not come along with fresh ESB pack. Moving to next step, you will get the chance of doing rest of configurations. Following image depicts the configuration of a sample WS-RM inbound endpoint.
At this point, you may already have some idea about the inbound endpoint. I have configured it to listen port 20940, in localhost. The Class of custom inbound should be “org.wso2.carbon.inbound.endpoint.ext.wsrm.InboundRMHttpListener” (without quotes). The configuration “inbound.cxf.rm.config-file” describes where you have placed the CXF server configuration file.
Messages coming into that specified port will go to “sequence” specified, in this case RMIn sequence and faulty messages will go to “fault” sequence. Other configurations related details are described at the official documentation .
You can do the above step straight forward by adding the inbound configuration directly from synapse-configuration.
<inboundEndpoint xmlns="http://ws.apache.org/ns/synapse" name="RM_INBOUND_NEW_EXT" sequence="RMIn" onError="fault" class="org.wso2.carbon.inbound.endpoint.ext.wsrm.InboundRMHttpListener" suspend="false"> <parameters> <parameter name="inbound.cxf.rm.port">20940</parameter> <parameter name="inbound.cxf.rm.config-file">repository/conf/cxf/server.xml</parameter> <parameter name="coordination">true</parameter> <parameter name="inbound.cxf.rm.host">127.0.0.1</parameter> <parameter name="inbound.behavior">listening</parameter> <parameter name="sequential">true</parameter> </parameters> </inboundEndpoint>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="RMIn" onError="fault"> <in> <property name="PRESERVE_WS_ADDRESSING" value="true"/> <header xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm" name="wsrm:Sequence" action="remove"/> <header xmlns:wsa="http://www.w3.org/2005/08/addressing" name="wsa:To" action="remove"/> <header xmlns:wsa="http://www.w3.org/2005/08/addressing" name="wsa:FaultTo" action="remove"/> <log level="full"/> <send> <endpoint> <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> </endpoint> </send> </in> <out> <send/> </out> </sequence>
Now you have completed the sample setting up. One more step to go. Let’s test this sample.
Running the sample
For that, ESB provides the client which can send reliable messages. Go to <ESB_HOME>/samples/axis2Client folder from terminal and apply following command:
ant stockquote -Dsymbol=IBM -Dmode=quote -Daddurl=http://localhost:20940 -Dwsrm=true
The command will send a getQuote request to ESB using WS-RM and projects the expected result.
As specified in the WS-RM spec , between client and ESB, several messages exchange in this scenario. If you use a packet capturing tool like Wireshark, you’ll see those messages. I have already attached the message flow , I observed to make it more clear. In brief, following messages are exchanged, you can follow the messages at text file with these points:
- “CreateSequence” message to initiate reliable messaging
- “CreateSequenceResponse” from ESB to client
- Actual message with data from client to ESB. This is the 1st and the last message in this case. ESB will send this message to backend server and get the response.
- “SequenceAcknowledgement” message along with the response from backend server send from ESB to client
- “TerminateSequence” message from client to ESB
Through this post, I wanted to introduce you to the new approach of implementing WS-ReliableMessaging. This implementation will come along with WSO2 ESB 4.9.0 release,and prior have different approach than this. Therefor this post will help anyone who is interested in doing WS-RM with newer ESB versions.
 WS-ReliableMessaging spec. – http://specs.xmlsoap.org/ws/2005/02/rm/ws-reliablemessaging.pdf
 CXF WS-RM – http://cxf.apache.org/docs/ws-reliablemessaging.html
 WSO2 ESB, Inbound Endpoint – https://docs.wso2.com/display/ESB490/Working+with+Inbound+Endpoints
 CXF WS-RM Inbound Endpoint – https://docs.wso2.com/display/ESB490/CXF+WS-RM+Inbound+Protocol
 Sample CXF configuration – http://www.filedropper.com/server_23
 Message flow – link-to-file