Cometd

definition

Comet is a World Wide Web application architecture in which a web server sends data to a client program (normally a web browser) asynchronously without any need for the client to explicitly request it. It allows creation of event-driven web applications, enabling real-time interaction which would otherwise require much more work. Though the term Comet was coined in 2006, the idea is several years older, and has been called various names, including server push, HTTP push, HTTP streaming, Pushlets, Reverse Ajax, and others.

Cometd on wikipedia

It's an implementation of the Bayeux protocol.

Use

Cometd is deployed by default with the portal (only trunk version). it's composed of a service and a webapp.

To get access to the cometd, you need to get a key associated with the login used in the portal.

public String getUserToken(String eXoId)

The connection has to be initialized, for doing so you can use the cometd widget available by default in the portal.

to send a message from the service to a user :

public void sendMessage(String eXoId, String channel, Object data)

Sample

you can find a sample here

To have it working :

  • deploy a trunk version of the portal
  • go to ~/java/portal/trunk/sample/application/cometd/ and execute exoproject --deploy=module
  • start the portal
  • load all the widgets and portlets
  • in a page, add the cometd widget and the portlet "CometdDemo"
  • in the widget click on init
  • in the CometdDemo portlet, type a message and click on "send", a pop up with your message will appear on the top right and disappear after 3 sec

What happened?

  • the portlet (JSR 286) sent an action with the message.
  • the action called the continuation service and sent the message to the user that had sent it
  • the service sent the message to the browser
  • the cometd client side received the message, and sent it to topics
  • in topic, the notification window listened to the topic "/eXo/portal/notification" so the notification window appeared.

improvements

  • replace the token system by oAuth would probably be good. not sure of how it is possible.
  • There is no method yet to broadcast a message on a channel to all the subscribers

Creator: jeremi joslin on 2008/03/20 15:17
Copyright (c) 2000-2009. Allright reserved - eXo platform SAS
1.6.13286