RTCQueue – The solution to a RESTful API, with stateful notification

Mercian Labels is a business based on real-time information. We have multiple operators who all access data and with a turnaround period of 3 days it is important that they all have access to the latest information as soon as it is available. From Artwork approval from clients through to order processing through the factory everyone relies on fast information which is up-to-date. To ensure that data is always up to date, no matter what client we are using, we built RTCQueue.

RTCQueue is a real-time communication server. It has been built in response to the underlying issue that REST-ful APIs are not able to broadcast changes made by clients to all applications real time.It has been built using WebSocket technology, an HTML5 technology designed for stateful communication with web pages. (See http://www.websocket.org/, RFC 6455). The server is built using a C# Mono, as a stateful TCP Listening service.

A service utilising the REST-ful API does not have to have knowledge of the RTCQueue protocol, for backwards/general library compatibility, and works as an independent service to simplify the system.

To run the system apply:

 

How does it work?

RTC messages are build using two distinct fields, a channel, made up of URI characters denoting a path (RFC 3986, Section 3.3), and an abstract string of data. These ensure that the data reaches the correct clients, without unnecessarily bombarding every listening client.

PHP

The RTCQueue is build into most of the classes using Boiler’s automatic class builder (build/generation/model.php through the patch above), and will, on building your application, already alert listening clients. This is done by linking into the Create(), getByAttributes() and Delete() functions of DBObject. This will automatically be implemented by any future database models.

For other messages a standalone library, \Library\RTCQueue, contains a ready built function for pushing messages to any RTCQueue:

RTCQueue::Send(“/my/channel”, array(“data”=>1));

Non-string data is converted using json_encode. Any channel name is valid as the first argument.

JavaScript

The client side work is done using the pre-build WebSocket libraries, which forms a part of all HTML5 enabled browsers.

The RTCQueue can be connected using the following code:

w = new WebSocket(“ws://localhost:8888/my/channel”);

The WebSocket handler listens on port 8888 of the remote host. We always send JSON, to keep things simple.

 

For more information on this code, please contact Will, using one of the methods on his profile.

This labelling news was spotted at Custom Printed Labels from the UK's best digital self adhesive label printing companies
Get the full story direct from source..