dotnet / MQTTnet

MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). The implementation is based on the documentation from http://mqtt.org/.
MIT License
4.48k stars 1.07k forks source link

Can't publish messages with QoS 'ExactlyOnce' with MQTTv5 #617

Closed perphilipp closed 5 years ago

perphilipp commented 5 years ago

When I publish a message after connecting with MqttProtocolVersion.V500 and setting the QoS to MqttQualityOfServiceLevel.ExactlyOnce, my HiveMQ Server disconnects the client immediately with the error message

Sent a PUBREL with payload.

If I switch the protocol to MqttProtocolVersion.V311, I can publish messages with MqttQualityOfServiceLevel.ExactlyOnce without the error.

My guess is that there is something wrong with the conversion of the PUBREL message to a MQTTv5 message-type.

Here is my code for connecting:

var options = new MqttClientOptionsBuilder()
                        .WithProtocolVersion(MqttProtocolVersion.V500)
                        .WithClientId("id")
                        .WithCredentials("user", "pass")
                        .WithTcpServer("localhost", 1883)
                        .Build();

await this.client.ConnectAsync(options);

Here is my code for publishing:

var message = new MqttApplicationMessageBuilder()
                .WithTopic("topic")
                .WithQualityOfServiceLevel(MqttQualityOfServiceLevel.ExactlyOnce)
                .WithPayload("payload")
                .Build();

await client.PublishAsync(message);

As I said, with .WithProtocolVersion(MqttProtocolVersion.V311) everything is fine. Since the problem seems to occour in the PUBREL, the other two QoS's are also fine.

I am using the Client from the NuGet 3.0.0 in a Xamarin Forms Project. The broker is a locally installed HiveMQ Community Edition version 2019.1.

Any help is greatly appreciated :)

chkr1011 commented 5 years ago

Hi, thank you for reporting that issue. Do you may have more information from HiveMQ? I am wondering what the "payload" may mean. MQTTv5 has some additional data in that packet in comparison to v3 but the term payload is strange.

But at least I can reproduce it with the public test broker from HiveMQ (without getting the error details). Best regards Christian

chkr1011 commented 5 years ago

I found the issue and fixed it. I will release a new version soon. Until that please use V311 instead.

perphilipp commented 5 years ago

Hi Christian, thank you very much for your fast response and fix! I'm looking forward to the next release. Best regards Philipp