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

Persistent sessions not working with V5 protocol #2090

Open
TorakikiITA opened this issue Oct 14, 2024 · 0 comments
Open

Persistent sessions not working with V5 protocol #2090

TorakikiITA opened this issue Oct 14, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@TorakikiITA
Copy link

Hello,
talking about the "simple" client, not the managed one, it does seem that the persistent session is not working with V5 protocol.
Here's the behavior (tested with multiple brokers to make sure it wasn't a broker issue):

  1. connect with V5 protocol, clean session set to false, clientId "my-persistent-clientid".
  2. subscribe a topic "topicTest/01", with qos 1 or 2.
  3. disconnect
  4. with another clientid, publish something on "topicTest/01" with qos 1 or 2.
  5. reconnect with the same settings of point 1: V5 protocol, clean session set to false, clientId "my-persistent-clientid"
  6. nothing is received

If I'm doing the same with V311 protocol, everything is working fine.

Here's the code for the subscriber:
`

var options = new MqttClientOptionsBuilder()
    .WithProtocolVersion(MqttProtocolVersion.V500)
    .WithClientId("my-persistent-clientid")
    .WithTcpServer("myhost", 8883) // Adjust broker host
    .WithCredentials("myusername", "mypwd") // Adjust username and password
    .WithCleanSession(false)
    .WithTlsOptions(
        new MqttClientTlsOptions
        {
            UseTls = clientSettings.UseTls,
            IgnoreCertificateChainErrors = true,
            IgnoreCertificateRevocationErrors = true,
            AllowUntrustedCertificates = true,
            CertificateValidationHandler = delegate { return true; }
        }
    )
    .Build();

var mqttFactory = new MqttFactory();
using var mqttClient = mqttFactory.CreateMqttClient();

Task local_ApplicationMessageReceivedAsync(MqttApplicationMessageReceivedEventArgs arg)
{
    Console.WriteLine($"Client id {arg.ClientId}, topic {arg.ApplicationMessage.Topic}, message received {arg.ApplicationMessage.ConvertPayloadToString()}");
    return Task.CompletedTask;
}

mqttClient.ApplicationMessageReceivedAsync += local_ApplicationMessageReceivedAsync;
mqttClient.ConnectAsync(options).Wait();
mqttClient.SubscribeAsync(topic: "topicTest/01", qualityOfServiceLevel: MqttQualityOfServiceLevel.ExactlyOnce).Wait();
Console.WriteLine("Press any key to exit.");
Console.ReadLine();
mqttClient.DisconnectAsync().Wait();

`

@TorakikiITA TorakikiITA added the bug Something isn't working label Oct 14, 2024
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

1 participant