0

I am using the mqttnet client in a sync way. Meaning that I am waiting for the result every time I am calling the publish async method.

the tread context is neither from UI nor from a MVC controller.

In fact I am creating a task using a BlockingCollection,

The blocking collection is called this way:

            foreach (var action in ActionBuffer.GetConsumingEnumerable(_cancellationToken.Token))
            {
                try
                {
                    if (res)
                    {
                        action.Invoke();
                    }
                }
                catch (Exception exception)
                {
                }
            }

the blocking collection is triggered from its own task

Task.Run(CallGetConsuming);

The action itself will simply call the mqttNet publishAsync method

var mqttApplicationMessage = new MqttApplicationMessageBuilder()
                        .WithTopic(mqttMessage.Topic)
                        .WithPayload(mqttMessage.Payload)
                   
        .WithQualityOfServiceLevel((MqttQualityOfServiceLevel)mqttMessage.Qos)
                        .Build();
        var task = _client.PublishAsync(mqttApplicationMessage);
        TaskUtil.WaitForSendingTask(task);

the waitforSending is just a normal task.wait.

Everything is working completely fine however when I am having some disconnection issue. Sometimes the wait method is hanging forever, I am on able to explain why. Is it an issue from the mqttnet library?

Note that I can reproduce it easily by calling disconnecting my internet connection while publishing a MQTT message.

I am using the version

MQTTnet.Extensions.ManagedClient

4.1.0.247

Any Idea, Thanks in advance, hak

hak
  • 49
  • 3

0 Answers0