test repo : https://github.com/akramesg/Grails5-Events
Hi, I'm trying to mimic the functionality of Grails2 events in Grails5 so have the following
in grails 2 the call would look like that :
event( 'article_published', article, [ fork: false, namespace: 'grails5.events', onError: {
EventReply reply ->
println('some reply')
} ] )
to have similar functionality I did this on G5
'''
package grails5.events
import grails.events.EventPublisher
class EventHandlingService implements EventPublisher {
// TODO Discover how to replicate the EventReply response functionality
// replaces previous functionality provided by grails events plugin.
def event(String topic, Object initialParameter, Map eventParams) {
log.debug("Publishing to topic $topic")
// join namespace and topic to a single String.
String newTopic = eventParams?.namespace+ '.' + topic
if (newTopic.startsWith('.'))
newTopic = topic
println("Sending to topic $newTopic")
// if fork is explicitly set to false
if (eventParams?.fork == false) {
try {
println "b4 sAndR"
sendAndReceive(newTopic, initialParameter, {Object result ->
log.debug "in sAndR result"
println "in sAndR result"
return result
})
println "after sAndR"
} catch (Exception ex) {
log.error("Error in sendAndReceive call",ex)
if (eventParams.onError) {
Closure callable = (Closure) eventParams.onError
callable()
}
}
} else {
try {
println('no fork so just notify the fkr')
notify(newTopic, initialParameter)
} catch (Exception ex) {
log.error("Error in notify call", ex)
if (eventParams.onError) {
Closure callable = (Closure) eventParams.onError
callable()
}
}
}
}
}
notify works ok when the fork = true but sendAndReceive doesn't seem to be blocking the code execution as it should be nor printing any line inside its result closure
any ideas !?
first question ever so apologies for any miss-formatting / or not being clear enough Thanks
It appears there is a bug where Grails never makes the call to invoke the response closure to sendAndReceive.
A issue has been logged with pull request for the fix : https://github.com/grails/grails-async/issues/39