Monday, November 10, 2008

Introduction to reliable messaging part 3

In this blog post, we will look at how you can send multiple application messages within a single sequence reliably using

WSClient API.  For this purpose WSClient has an option named willContinueSequence. If you intend to send only a since application message within your reliable sequence, then you do not need to touch this option. However, when sending multiple application messages, you need to use it as follows.

1. When sending the first message, set willContinueSequence=TRUE in WSClient.

2. Send your application messages by using WSMessage object.

3. When you want to send the final application message to be sent within the reliable sequence, set the option lastMessage to true.

Here is a code example demonstrating this.

Step 1. First create an application message.

$requestPayloadString = <<<XML
    <ns1:pingString xmlns:ns1="http://wso2.org/wsfphp/samples/reliable">
        <text>Hello World!</text>
    </ns1:pingString>
XML;

Step 2. Create a WSClient object with willContinueSequence option set to TRUE

$client = new WSClient(array( "reliable" => TRUE, "useWSA" => TRUE, "willContinueSequence" => TRUE));

Step 3. Create and Send WSMessage objects containing application messages.

$message = new WSMessage($requestPayloadString,
           array( "to" => "http://localhost/samples/reliable/ping_service_rm.php",
                  "action" => http://wso2.org/wsfphp/samples/pingString));

$client->send($message);

$message1 = new WSMessage($requestPayloadString,
            array( "to" => "http://localhost/samples/reliable/ping_service_rm.php",
                   "action" => "http://wso2.org/wsfphp/samples/pingString"));

    $client->send($message1);

Step 4. When you want to send the last application message, set the option lastMessage to true in WSMessage object.

$message2 = new WSMessage($requestPayloadString,
    array( "to" => "http://localhost/samples/reliable/ping_service_rm.php",
           "action" => "http://wso2.org/wsfphp/samples/pingString",
           "lastMessage" => TRUE));

$client->send($message2);

Note that this is a ping service and hence the use of the method send in WSClient. You can similarly use request method as well.

No comments:

Post a Comment