MQTTnet
MQTTnet copied to clipboard
订阅高并发topic场景会存在内存泄漏
Verification
// See https://aka.ms/new-console-template for more information
using MQTTnet;
using MQTTnet.Client;
Console.WriteLine("Hello, World!");
var mqttFactory = new MqttFactory();
var mqttClient = mqttFactory.CreateMqttClient();
var mqttClientOptions = new MqttClientOptionsBuilder()
.WithTcpServer("10.132.105.8")
.WithClientId("ebb46a457522466882bdb6d316fa29f3")
.Build();
// Setup message handling before connecting so that queued messages
// are also handled properly. When there is no event handler attached all
// received messages get lost.
mqttClient.ApplicationMessageReceivedAsync += e =>
{
Console.WriteLine("Received application message.");
Thread.Sleep(500);
return Task.CompletedTask;
};
await mqttClient.ConnectAsync(mqttClientOptions, CancellationToken.None);
var mqttSubscribeOptions = mqttFactory.CreateSubscribeOptionsBuilder()
.WithTopicFilter(
f =>
{
f.WithTopic("/iothub/#");
})
.Build();
await mqttClient.SubscribeAsync(mqttSubscribeOptions, CancellationToken.None);
Console.ReadLine();
topic: /iothub/a 这个主题一秒钟有100条数据包
Google Translate: 'Das Abonnieren von Themenszenarien mit hoher Parallelität kann zu Speicherverlusten führen'
@colincodefirst First I would suggest to replace Thread.Sleep(500); with await Task.Delay(TimeSpan.FromMilliseconds(500)); Does this change anything?
@colincodefirst First I would suggest to replace Thread.Sleep(500); with await Task.Delay(TimeSpan.FromMilliseconds(500)); Does this change anything?
I agree, the rest of the code looks good for me.