简体   繁体   中英

How to dynamically create a new a Topic using Events Push plugin

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

new Event(topic:'anotherTopicName',...)

which will allow me to call from a service :

    import grails.events.*

    class MyService {

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

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

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){

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM