nanomq版本:v0.23.7-10
cyclone_dds版本:v0.11.0
操作系统:WSL2 Ubuntu20.04
按照配置教程编译运行没有任何问题:https://nanomq.io/docs/zh/latest/gateway/dds.html
自己使用原生cyclonedds编写发布者和订阅者
发布者代码如下:
#include "dds_type.h" // 由 idlpp 生成
#include "dds/dds.h"
#include <stdio.h>
#include <string.h>
int main() {
dds_qos_t *qos = dds_create_qos();
dds_entity_t participant = dds_create_participant(DDS_DOMAIN_DEFAULT, qos, NULL);
dds_entity_t topic = dds_create_topic(participant, &example_struct_desc, "MQTTCMD/topic1", NULL, NULL);
dds_entity_t writer = dds_create_writer(participant, topic, NULL, NULL);
example_struct msg;
msg.int32_test = 1;
while (1)
{
dds_write(writer, &msg);
printf("Cyclone: Sent: id=%d\n", msg.int32_test);
dds_sleepfor(DDS_MSECS(1000));
msg.int32_test+=1;
}
return 0;
}
使用cyclone_dds 官方的idlc工具进行序列化
idl文件如下
@extensibility(APPENDABLE)
struct example_struct
{
int32 int32_test;
};
我确保发布主题没有错误
使用命令行输入
nanomq_cli dds pub -t "MQTTCMD/topic1" --struct "example_struct" -m '{
"int32_test":123
}'
./nanomq_cli dds sub -t “MQTT/topic1” --struct “example_struct”
启动的客户端可以正常收到数据
DDS Proxy 的idl和上面idl完全一致,并且已经正常编译运行