CometD 1.0 Released, Work Begins on 2.0

DZone 's Guide to

CometD 1.0 Released, Work Begins on 2.0

· Web Dev Zone ·
Free Resource
Any application that receives server-side events such as online games, stock information, sport results, content sharing, etc. can use the CometD project libraries to greatly simplify development.  CometD is an HTTP event routing bus for AJAX web applications.  Using Comet, an AJAX Push technology pattern, CometD facilitates multi channel messaging between client and server, and vice versa.  The bus implements the publish/subscribe asynchronous paradigm of the Bayeux protocol in JavaScript, Java, Perl, Python and other languages.  The Dojo Foundation houses the CometD project, which recently unveiled version 1.0.  Work has already begun on version 2.0.

The final release of CometD 1.0 provides the core operation of the Bayeux protocol  by delivering messages to all subscribers for a particular channel, either locally in the server, remotely in the client, or remotely in the client of a clustered server.

JavaScript subscription must provide a callback to handle messages:
// Some initialization code
var subscription1 = cometd.addListener('/meta/connect', function() { ... });
var subscription2 = cometd.subscribe('/foo/bar/', function() { ... });

// Some de-initialization code
To publish a method in JavaScript, simply pass the channel name and the message:
cometd.publish('/mychannel', { wibble: { foo: 'bar' }, wobble: 2 });

There is now a robust client-side CometD implementation for jQuery in 1.0.  With bindings for Dojo and jQuery, most of the CometD implementation is now a pure-JavaScript file.  The Dojo and jQuery toolkit bindings allow developers to use the JavaScript Cometd API as a first class citizen in both toolkits.

How you use it in Dojo:
dojox.cometd.publish('/mychannel', { mydata: 'foobar' });

How you use it in jQuery:
$.cometd.publish('/mychannel', { mydata: 'foobar' });

Other key features of CometD include lazy messages and clustering.  CometD is inteded to deliver messages to clients from the server with low latency,  but not all messages require low latency.  Lazy messages can be queued for a client and they won't wake up the long poll of that client.  A lazy message will only be delivered when a non-lazy message is sent to that client, or when the long poll naturally times out.  CometD 1.0 also supports private message delivery.  For clustering, CometD 1.0 servers can be aggregated with Oort.  The Oort collection of extensions allows CometD servers to recognize and monitor each other for efficient load balancing.  CometD client and server APIs support the concept of batching.  Although it's only the 1.0 release, CometD has already been deployed in many applications that required scaling from a few users to potentially millions of users.

According to a post on the CometD developers' Google group, work has already started on CometD 2.0.  Greg Wilkins posted a message to everyone saying:  
"Simone and I have started working on cometd 2.0, which is a refactor of the
code base of cometd1.0 with the two purposes of:
Cleaning up dead end ideas that hang over from the development of cometd and bayeux
To support websocket and other new transports.

The branch for this is  https://svn.cometd.org/branches/cometd2
and it will be HIGHLY experimental and unstable for some time."

The HTML5 Websocket specification defines a full, two-way communications channel that operates over a single socket and is exposed via a JavaScript interface in HTML 5 compliant browsers.  The bi-directional capabilities of Comet and AJAX are not native to the browser currently.

One disadvantage of the CometD project is that it does not provide any direct IDE support.  However, a Primer will explain how to setup a project with Maven, and the major Java IDEs have a great support for Maven.  Another disadvantage for some users is that the Python and Perl implementations don't have enough active maintainers, and are not production ready.  Those who want to contribute to the Python and Perl implementations can start by joining CometD's mailing list.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}