New extension proposal: SAM - Simple Asynchronous Messaging

From: Date: Fri, 29 Sep 2006 10:28:42 +0000
Subject: New extension proposal: SAM - Simple Asynchronous Messaging
Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-4198@lists.php.net to get a copy of this message
Many enterprises both large and small rely on asynchronous messaging and queueing infrastructures to connect the various pieces of their business systems. For many the messaging infrastructure is a key element of their systems and will continue to be so for the foreseeable future. Currently connecting PHP scripts to this infrastructure is not simple or convenient. The aim of the SAM extension is to open up the messaging infrastructure to the PHP scripting environment by providing an API that allows the most common and simple messaging operations to be accomplished with the minimum of fuss. At the same time the API has to allow for the fact that many of these messaging infrastructures are connecting legacy systems and thus it must be possible for someone skilled in messaging technologies to access the low-level details of messages and the associated gorp. Given the ever increasing popularity of PHP the SAM extension can make deploying solutions for a number of use cases very simple where today they are complex. The use cases range from the simple ability for a web page to post a request to an asynchronous back-end process for later processing, such as requesting a bank statement by mail, to complex AJAX-based solutions that exploit the pub/sub mechanisms available with some messaging systems. As an example a PHP script could deliver a simple text string message, possibly formatted as XML, to a message queue using the following code snippet: $conn = new SAM_Connection(); $conn->connect('wmq'); $msg = new SAM_Message('A very simple text message from SAM'); $conn->send('queue://myqueue', $msg); If we add a little error handling to the example it looks a bit more complicated but not much: $conn = new SAM_Connection(); if (!$conn->connect(SAM_WMQ)) { echo 'Oh dear it failed. What shall we tell the customer'; } else { $msg = new SAM_Message('A very simple text message from SAM'); if (!$conn->send('queue://myqueue', $msg)) { echo 'Oh dear it failed. What shall we tell the customer'; } else { echo 'Your request has been submitted. Thank you'; } } Obtaining a result from a queue is equally simple. Extending the previous example we could have: $conn = new SAM_Connection(); $conn->connect(SAM_WMQ, array(SAM_HOST => myhost.mydomain.com,
                           SAM_PORT => 1414,
                           SAM_BROKER => mybroker) );
$msg = new SAM_Message('A very simple text message from SAM'); $msg->header->SAM_REPLY_TO = 'queue://return_queue'; $token = $conn->send('queue://send_queue', $msg); $msg = $conn->receive('queue://return_queue',
                array(SAM_WAIT => 5, SAM_SELECTOR => $token));
In this example an additional property is associated wit the message being sent which identifies the name of the queue on which the application will look for a response. Also the returned value from the "send" operation is a token that can be used as a selector to identify the reply message and this is passed in on the "receive" method along with a timeout value which limits how long the script waits for a response. To remain responsive a script delivering a user interface cannot block waiting for a response for unreasonable times and thus the timeout value can be used to allow the script to return without the result. The "token" is a string that can be passed in a URI or within the session to allow a subsequent different script to retrieve the result at a later point. This also allows the SAM extension to be used to support asynchronous applications using the AJAX pattern. At this point we have documented almost all of the API and have an implementation of a range of basic send/receive functionality usable on all the IBM messaging product family. We have not yet implemented the publish and subscribe capabilities but plan to do so. The current level of documentation can be reviewed on our temporary website, http://project-sam.awardspace.com. The code could be made available under and Apache 2.0 license which I believe is compatible with the PECL scheme of things. I and a colleague would sign up to be committers on the project and to push the implementation forward. As background there is an existing "mqseries" extension package, created by Philippe Tjon - A - Hen, which maps the IBM MQI interface to PHP. This looks to be a fairly complete in terms of coverage and I have had some discussions with Philippe on his plans for taking it forward. He has no plans to provide any simpler API or to increase the coverage to anything other than the MQSeries products that support the MQI and he sees a separate SAM extensions as a reasonable approach. I would appreciate you comments on this proposal. Dave

« previous php.pecl.dev (#4198) next »