本文介绍了如何使用Events Push插件动态创建新的Topic的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了创建一个事件的主题,我需要在conf / MyEvents.groovy文件中声明如下:

To create a topic for an event I need to declare this in my conf/MyEvents.groovy file as follows:

events = {
    "topicName"  browser: true  
}

使用服务器推送两件事,推送聊天消息到客户端,并推送通知给客户端。

I am wanting to use the server push for two things, pushing chat messages to a client and also for pushing notifications to a client.

以前者为例,我需要为运行时在聊天系统中实例化的每个对话创建一个新主题,以便可以将消息推送给每个对话参与者,所以沿着

Using the former as an example, I will need to create a new Topic for each conversation that is instantiated in the chat system at runtime, so that messages can be pushed to each of the conversation participants, so along the lines of

新的事件(topic:'anotherTopicName',...)

这将允许我从服务:

which will allow me to call from a service :

    import grails.events.*

    class MyService {

       def doSomething(){
            ...
            event(topic:'anotherNewTopic', data:data)           
       }
    }

有没有一种方法可以让我创建一个新的Event主题?或者有另一种方法来实现这个使用事件推送

Is there a method that will allow me to create a new Event topic? Or is there another way to implement this using Events Push

推荐答案

我刚刚做了类似的事情。我需要根据已登录的用户显示一些通知,所以我在MyEvents.groovy中设置了这个:

I've just done something similar. I needed to show some notifications based on the user that had logged in, so I set this in MyEvents.groovy:

events = {
   'newNotification_*' browser:true
}

当我需要发送通知:

And when I need to send the notification:

event topic:"newNotification_${userId}",data:n

然后在我的浏览器中,我可以听到类似这样的通知:

Then in my browser I can listen to those notifications with something similar to this:

grailsEvents.on("newNotification_"+myUser,function(data){

这篇关于如何使用Events Push插件动态创建新的Topic的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 13:29