@groovy.transform.CompileStatic class CometdService extends Object
CometD 消息服务,需配合 cometd 插件使用
| Modifiers | Name | Description |
|---|---|---|
class |
CometdService.CometdClosureListener |
基于闭包的监听器 |
class |
CometdService.CometdServiceListener |
基于Service方法的监听器 |
| Modifiers | Name | Description |
|---|---|---|
static Object |
aliasOverridingOrder |
| Type | Name and description |
|---|---|
org.cometd.server.BayeuxServerImpl |
bayeux |
| Type | Name and description |
|---|---|
void |
afterPropertiesSet()初始化 |
Boolean |
hasSubscriber(String channel)判断频道是否有监听者 |
void |
publish(String channel, Object data)发布一条消息 |
void |
publish(String cometUrl, String channel, Object data)发布一条消息到远程服务器上 |
void |
publish(DomainApplication application, String channel, Object data)发布一条消息到其他应用 |
org.cometd.bayeux.client.ClientSessionChannel$MessageListener |
subscribe(String channelName, Closure cls)监听频道 |
org.cometd.bayeux.client.ClientSessionChannel$MessageListener |
subscribe(String cometUrl, String channelName, Closure cls)监听远程频道 |
org.cometd.bayeux.client.ClientSessionChannel$MessageListener |
subscribe(DomainApplication application, String channelName, Closure cls)监听其他应用的频道 |
void |
unsubscribe(String channelName, org.cometd.bayeux.client.ClientSessionChannel$MessageListener listener)取消对某个频道的监听 |
void |
unsubscribe(String cometUrl, String channelName, org.cometd.bayeux.client.ClientSessionChannel$MessageListener listener)取消对某个远程频道的监听 |
void |
unsubscribe(DomainApplication application, String channelName, org.cometd.bayeux.client.ClientSessionChannel$MessageListener listener)取消对某个其他应用频道的监听 |
void |
unsubscribe(String channelName)取消频道下所有的监听器 |
void |
unsubscribe(String cometUrl, String channelName)取消远程频道下所有的监听器 |
void |
unsubscribe(DomainApplication application, String channelName)取消某个应用频道下所有的监听器 |
| Methods inherited from class | Name |
|---|---|
class Object |
Object#wait(long, int), Object#wait(long), Object#wait(), Object#equals(Object), Object#toString(), Object#hashCode(), Object#getClass(), Object#notify(), Object#notifyAll() |
初始化
判断频道是否有监听者
发布一条消息
channel - 频道名称(以/开头,否则会抛出“Invalid channel id”异常)。
如果需要发布给集群里所有成员服务器,则频道名称以 /broadcast/ 作为前缀即可(见 CometdGrailsPlugin)。data - 发布的数据,常用的如map、字符串等可以序列化的对象发布一条消息到远程服务器上
发布一条消息到其他应用
监听频道
channel - 频道名称(以/开头,否则会抛出“Invalid channel id”异常)cls - 处理接收到的数据的闭包,如 {data-> println data}监听远程频道
监听其他应用的频道
取消对某个频道的监听
channel - 频道名称(以/开头,否则会抛出“Invalid channel id”异常)listener - 监听器取消对某个远程频道的监听
取消对某个其他应用频道的监听
取消频道下所有的监听器
取消远程频道下所有的监听器
取消某个应用频道下所有的监听器