将 Grails 2 事件处理升级到 Grails 5

upgrading Grails 2 event handling to Grails 5

测试回购:https://github.com/akramesg/Grails5-Events

您好,我正在尝试在 Grails5 中模仿 Grails2 事件的功能,因此具有以下内容

在 grails 2 中,调用看起来像这样:

event( 'article_published', article, [ fork: false, namespace: 'grails5.events', onError: { 
   EventReply reply ->
      println('some reply')
} ] )

为了获得类似的功能,我在 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()
                }
            }
        }

    }
}

当 fork = true 时通知工作正常,但 sendAndReceive 似乎没有阻止代码执行,也没有在其结果闭包中打印任何行

有什么想法!?

第一个问题,对于任何格式错误/或不够清楚,我们深表歉意 谢谢

似乎存在一个错误,Grails 从不调用以调用对 sendAndReceive 的响应闭包。

修复的拉取请求中记录了一个问题:https://github.com/grails/grails-async/issues/39