如题,emqx版本:5.3
有这样的topic和消息内容,如下:
# topic
v2x/this_is_vehicle_id/sides
# 消息内容
{
"data_base64": "IUYDFHRlc3QYMgZXD==",
"datacontenttype": "application/x-protobuf",
"dataschema": "baiduType",
"id": "ui74diuy4-6944-49c2-af2b-iu73nmc0983n7",
"priority": "B01",
"specversion": "1.0",
"time": "2024-09-23T18:59:25.632",
"token": "eyJ4NXQiOiI4NTJlMTQwNjU5ZmM3ZDY1ZWI0OWFhYzczNDEwMDJiMDE5Njg0Njg4A",
"ttl": 120000,
"type": "resquest"
}
重写要求
1、topic中的id为发送topic中的中间车辆id
2、req_id是发送消息体中的id
3、随机生成uuid4
4、time是当前时间+08:00
# topic
v2x/this_is_vehicle_id/messages/ack
# 消息内容
{
"version": "v1",
"id": "541bbcbe-f0d2-4f06-8901-35da0675e78f",
"time": "2024-09-23T18:59:25.632",
"req_id": "ui74diuy4-6944-49c2-af2b-iu73nmc0983n7",
"message": "ack"
}
重写方法:
SELECT
payload.id,
uuid_v4() as u4id,
now_rfc3339('millisecond') as timenow,
nth(2, split(topic, '/') as vinid
FROM
v2x/+/sides
# topic
v2x/${vinid}/messages/ack
{"version":"v1","id","u4id","time":"${timenow}","req_id":"${payload.id}","msg":"ack"}