Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only QOS0 retained messages are received by the client upon subscription. #1434

Closed
jkompis opened this issue Jun 15, 2022 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@jkompis
Copy link

jkompis commented Jun 15, 2022

Describe the bug

Retained messages published with other than QOS 0 aren't received by the client upon subscription.

Which component is your bug related to?

  • Server

To Reproduce

See code example.

Expected behavior

Upon subscription client will received all retained messages not only ones with QOS 0.

Code example

using System.Text;
using MQTTnet;
using MQTTnet.Client;
using MQTTnet.Diagnostics;
using MQTTnet.Packets;
using MQTTnet.Protocol;


// prepare server
var logger = new MqttNetEventLogger();
logger.LogMessagePublished += (_, eventArgs) =>
{
    Console.WriteLine(eventArgs.LogMessage.Message);
};
var factory = new MqttFactory(logger);
var serverOptions = factory.CreateServerOptionsBuilder()
    .WithDefaultEndpoint()
    .Build();
var mqttServer = factory.CreateMqttServer(serverOptions);

await mqttServer.StartAsync();

var clientOptions = factory.CreateClientOptionsBuilder()
    .WithTcpServer("127.0.0.1", 1883)
    .WithCleanSession()
    .Build();


// publish retained message
var writeClient = factory.CreateMqttClient();

await writeClient.ConnectAsync(clientOptions);
await writeClient.PublishAsync(new MqttApplicationMessage
{
    Topic = "test_topic/0",
    Payload = Encoding.UTF8.GetBytes(@"{""hello"":0}"),
    Retain = true,
    QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce
});
await writeClient.PublishAsync(new MqttApplicationMessage
{
    Topic = "test_topic/1",
    Payload = Encoding.UTF8.GetBytes(@"{""hello"":1}"),
    Retain = true,
    QualityOfServiceLevel = MqttQualityOfServiceLevel.AtLeastOnce
});
await writeClient.PublishAsync(new MqttApplicationMessage
{
    Topic = "test_topic/2",
    Payload = Encoding.UTF8.GetBytes(@"{""hello"":2}"),
    Retain = true,
    QualityOfServiceLevel = MqttQualityOfServiceLevel.ExactlyOnce
});
await writeClient.DisconnectAsync();


// create new client and subscribe
var readClient = factory.CreateMqttClient();

readClient.ApplicationMessageReceivedAsync += eventArgs =>
{
    Console.WriteLine($"message received {eventArgs.ApplicationMessage.Topic}");
    return Task.CompletedTask;
};

await readClient.ConnectAsync(clientOptions);
await readClient.SubscribeAsync(new MqttTopicFilter
{
    Topic = "test_topic/+",
    QualityOfServiceLevel = MqttQualityOfServiceLevel.ExactlyOnce
});


// give it some time 
await Task.Delay(5000);

await readClient.DisconnectAsync();
await mqttServer.StopAsync();
@chkr1011
Copy link
Collaborator

Please test with version 4.0.1.184 from the MyGet feed (see Readme). I fixed the issue in this version. If it works I will release a hotfix version soon.

@jkompis
Copy link
Author

jkompis commented Jun 16, 2022

It works as expected with 4.0.1.184.

@jkompis jkompis closed this as completed Jun 16, 2022
@jkompis
Copy link
Author

jkompis commented Jun 16, 2022

Sorry not sure it it was supposed to be closed by me and now so I reopen it.

@jkompis jkompis reopened this Jun 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants