grails Comet插件

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:

  1. grails create-app ${applicationName}
  2. cd ${applicationName}
  3. grails install-plugin cometd
  4. grails run-app
  5. 访问示例位置: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
    • see the docs of bayeux

版本与兼容性

  • 版本 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

 

 

 

近日弄个例子上来

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值