开源工具技巧DTeam团队日志程序员

dgate新特性:EventBusBridge Mock

2017-12-15  本文已影响134人  胡键

由于简单同时又强大的Mock特性,dgate在我的项目中除了作为简单的API网关,它也承担着面向前端的Mock Server作用,保证前后端开发同步进行。最近,因为项目的需要,顺手给它增加了一个新的Mock特性:EventBusBridge。

使用很简单,DSL的例子如下:

apiGateway {
    port = 7001
    host = 'localhost'

    urls { ... }

    eventBusBridge {
        urlPattern ='/eventbus/*'
        publishers {
            'target_address' {
                expected = {
                    [timestamp: Instant.now()]
                }
                timer = 1000
            }
        }
        consumers {
            'consumer_address' {
                target = "target_address"
                expected = [test: true] // 或者 {message -> ...}
            }
        }
    }
}

语法很简单,与Mock HTTP几乎一致。其中:

对于expected,它既可以为一个固定的值,也可以为一个闭包。当为闭包时,其返回值为mock结果。同时,对于consumers中的expected,闭包的入参为event message。


相关链接:

上一篇 下一篇

猜你喜欢

热点阅读