question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ManagedClient WithCleanSession

See original GitHub issue

I’m trying to use the clean session with the managed client

var options = new ManagedMqttClientOptionsBuilder()
    .WithAutoReconnectDelay(TimeSpan.FromSeconds(5))
    .WithClientOptions(new MqttClientOptionsBuilder()
        .WithClientId(Guid.NewGuid().ToString())
        .WithTcpServer(configuracion.Servidor)
        .WithCredentials(configuracion.Username, configuracion.Password)
        .WithKeepAlivePeriod(TimeSpan.FromSeconds(60))
        .WithCleanSession(false) //sesion persistente
        .Build())
    .Build();
var mqttClient = new MqttFactory().CreateManagedMqttClient();

await mqttClient.SubscribeAsync(new TopicFilterBuilder()
    .WithTopic(configuracion.Topic)
    .WithExactlyOnceQoS()
    .Build());

await mqttClient.StartAsync(options);

I have tried to connect to 2 different HiveMQ brokers with the following error:

Error: System.NotSupportedException: The managed client does not support existing sessions.
   at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.StartAsync(IManagedMqttClientOptions options)
   at MQTT_client.MQTT.ManageMQTTClient()

If I use other client, I can connect successfully using cleansesion to that HiveMQ broker.

So, is it not supported to use cleansession with managed client? or it could be done in a different way using the managed client?

I’m using the 3.0.2 MQTTnet version

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
chkr1011commented, Jul 2, 2019

No that is not supported yet but already on the feature list.

0reactions
chkr1011commented, Jul 4, 2019

No not yet. Also will this feature come with some drawbacks because it cannot cover all use cases. But you can always use the regular MqttClient. The ManagedMqttClient is just a small extension which reconnects automatically etc. With that base client you can do everything (including reuse of existing sessions).

Read more comments on GitHub >

github_iconTop Results From Across the Web

ManagedClient WithCleanSession · Issue #687
I'm trying to use the clean session with the managed client var options = new ManagedMqttClientOptionsBuilder() .
Read more >
ManagedClient Memory Leak - Apple Community
ManagedClient is increasing 400-500 MB of RAM usage per hour until it reaches many GB in size and the machine starts to suffer....
Read more >
Unable to add a client certificate in MqttNet Managed Client
getting a little problem I'm unable to add certificate with client. it is giving me error of type mismatch. this is my code....
Read more >
MQTT Publishing and Subscribing Messages to ...
I will be using CloudMQTT MQTT Broker Free Instance for this article. Add "MQTTnet.Extensions.ManagedClient" Nuget Package. The Latest DZone ...
Read more >
C# Demo Usage Guide - 华为云
ManagedClient v3.0.11 is an extension library that uses MQTTnet to provide additional functions for the ... WithCleanSession(false) .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found