(Quick Reference)
on([String namespace ,] String topic, Closure callback)
Available in Controllers, Domains and Services This method dynamically registers a closure handler for a given namespace/topic. Default Namespace is
app if undefined.
It returns a stringified
ListenerId.
Usage
class SomeController{
def testInlineListener = {
//register with 'logout' topic on 'app' default namespace
def listener = on("logout") {User user ->
println "test $user"
}
render "$listener registered"
}
def testInlineListener2 = {
//register a 'gorm' namespaced handler on 'afterInsert' topic.
def listener = on("gorm", "afterInsert") {Book book ->
println "test $book"
}
render "$listener registered"
}
}
Arguments
Name | Mandatory | Default | Description |
---|
namespace | false | app | A string scope |
topic | true | | A string topic to listen for |
callback | true | | A closure handler which takes an EventReply as an argument |