本次的目标时build echo.go为插件,并在rule中使用它。
在执行到“创建规则”时出现错误: plugin.Open("/usr/local/kuiper-0.1-linux-x86_64/plugins/functions/Echo.so"): plugin was built with a different version of package internal/cpu
具体操作流程如下:
编写.go文件
直接使用echo.go这个示例文件,不加修改
build为插件
因为用go get命名获取了github上的kuiper项目,所以echo.go位于$gopath/src/github.com/emqx/kuiper/plugins/functions/echo.go
路径下,build为.so文件:
go build --buildmode=plugin -o plugins/functions/Echo.so plugins/functions/echo.go
编写rule文件
在kuiper安装目录下创建如下文件
ruleechoo.txt
{
"sql": "SELECT echo(temperature) from demoecho",
"actions": [
{
"log": {}
}]
}
开始测试
- 启动kuiper
bin/server
- 创建规则rule
bin/cli create rule ruleecho -f ruleecho.txt
执行这一步时报错:
Parse SQL SELECT echo(temperature) from demoecho error: cannot open /usr/local/kuiper-0.1-linux-x86_64/plugins/functions/Echo.so: plugin.Open("/usr/local/kuiper-0.1-linux-x86_64/plugins/functions/Echo.so"): plugin was built with a different version of package internal/cpu (previous failure).
查看rule,已经创建好了
启用rule,仍然报错:
暂时忽略错误,继续执行
- 创建流stream
bin/cli create stream demoecho '(temperature bigint) WITH (FORMAT="JSON", DATASOURCE="echo")'
- mosquitto发送数据
mosquitto_pub -h localhost -t "echoo" -m "{\"temperature\":30}"
- 查看stream.log,没有收到消息