Cometd is a scalable HTTP-based event routing bus that uses a Ajax Push technology pattern known as Comet. The term 'Comet' was coined by Alex Russell in his post Comet: Low Latency Data for the Browser.The Plugin setup a Cometd servlet and includes all the demo programs from the original Cometd distribution.compatibility note The cometd demo works in any version. but there is a bug that caused the Cometd Servlet to fail when any Grails controller is added to the project. Please use Grails 1.1 RC1 or later for Grails development.
Features
- included everything from the cometd distribution, including all libraries and demo programs.
- With two additional classes for 'bridging' Cometd and the Spring-based Grails
- SpringCometdServlet
- extends ContinuationCometdServlet
- it is created to skip the init() method in AbstractCometdServlet that load the init-parameters from web.xml. This implementation loads the parameters from Spring configuration instead.
- filters are not loaded from a json file, but is also defined in Spring configuration. (remarks: this feature is not properly tested
!)
- SpringBayeux
- A singleton bayeux instance is the core Bayeux server component
- SpringBayeux extends ContinuationBayeux
- The SpringBayeux is expected to be constructed in Spring before the initialization of servlet context.
- Dynamically adding servlet and servleting mapping, and create a singleton Bayeux in Spring
- Servlet mapping
- by default, the Cometd servlet are mapped to *.cometd, /cometd, /cometd/*, and /plugins/cometd-${version}/cometd (for running the demo programs)
- the 'cometd' namespace is configurable with 'cometd.namespace' system property
- Spring
- The Bayeux instance is named 'bayeux' in Spring's application context
usage
installation
For non-Grails users, download a Grails binary distribution and setup environmental variables according to the Grails installation procedure, then run the following commands to create your Cometd project and access the demo:- grails create-app ${applicationName}
- cd ${applicationName}
- grails install-plugin cometd
- grails run-app
- access the demo at http://localhost:8080/${applicationName}/plugins/cometd-${pluginVersion}/
configuration
- from 0.1.2, the following configurations are available:
plugins { cometd { 'servlet-mapping' { namespace = 'cometd' } 'noCacheFilter' { disable = false; //the filter add HTTP Header for disabling HTTP cache } 'cometdService' { // Cometd provides extra functions including logging and client tracking disable = false; // disable } } } - System property is no longer supported.
- logging
debug consoleAppender: 'org.grails.plugins.cometd'
send and receive message to/from cometd channels
- a Spring bean named 'bayeux' which represents the Cometd server and you will interact with it in your application
- see see API doc of AbstractBayeux
- In Grails artifacts, you could inject the bayeux simply by:
class MyChatService{ def bayeux } - receiving message at the server side
- see the CometdService.init() as an example
- sending messaege at the server side
- see the docs of bayeux
Version and Compatiability
- version 0.1.*
- Support Grails 1.1 RC1 for Grails development
- included cometd-jetty 6.1.12 / cometd-api 1.0beta4
- This plugin uses cometd-jetty, quote from the cometd mail list:
- "Note that the jetty cometd servlet will run on tomcat. It just wont use the async features of tomcat, but it will still handle many hundreds of simultaneous users (good for many apps)."
Links
- Cometd Official Site
- Other related projects
- Kaazing claims to provide an alternative to CometD http://www.kaazing.org/



