0

现在我可以使用这个发布消息

MqttServerClient client = MqttServerClient.withPort(broker, "", 1883); //connect broker

//create message
final builder = MqttClientPayloadBuilder();
builder.addString(message);

client.publishMessage(topic, MqttQos.atLeastOnce, builder.payload); //publish message

但是如何将发布的消息设置为保留。

4

1 回答 1

0

根据文档,语法是:

int publishMessage(

    String topic,
    MqttQos qualityOfService,
    Uint8Buffer data,
    {bool retain = false}

) 

所以你publish需要:

client.publishMessage(topic, MqttQos.atLeastOnce, builder.payload, true);
于 2022-02-26T04:02:51.360 回答