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.
该插件建立了一个Cometd servlet并包含所有原来Cometd版本的例子程序。
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.
compatibility note The cometd例子在任何版本下都有效。但有一个小问题,当任何Grails controller 添加到工程时,Cometd Servlet会引起失败。请使用Grails 1.1 RC1或更新版本。
特点:
- included everything from the cometd distribution, including all libraries and demo programs.
- With two additional classes for 'bridging' Cometd and the Spring-based Grails
- 使用2个额外的类作为桥接Cometd和基于 Spring的 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.
- 动态增加servlet and servleting mapping,在spring中创建一个单例的Bayeux
Dynamically adding servlet and servleting mapping, and create a singleton Bayeux in Spring
-
- Servlet mapping
- 默认的, 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
- the 'cometd' namespace是可以配置的,位于系统属性中的'cometd.namespace'。
- Spring
- The Bayeux instance is named 'bayeux' in Spring's application context
用法
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}/
- 自0.1.2版本起,如下配置是可用的。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'
发送和接收消息与cometd channels
send and receive message to/from cometd channels
- 一个名为'bayeux'的spring bean,它代表Cometd server,你将在你的应用程序中和他交互
- a Spring bean named 'bayeux' which represents the Cometd server and you will interact with it in your application
o class MyChatService{
o def bayeux
o }
- 服务端接收消息receiving message at the server side
- 服务端发送消息sending messaege at the server side
版本与兼容性
- 版本 0.1.*
- 支持 Grails 1.1 RC1 for Grails开发
- 包含 cometd-jetty 6.1.12 / cometd-api 1.0beta4
- 该插件使用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)."
链接
作者: Mingfai Ma (mingfai.ma (at-no-spam) gmail.com)
Close
近日弄个例子上来