MQTTnet icon indicating copy to clipboard operation
MQTTnet copied to clipboard

评论订阅接收保留消息不全,保留消息里有3000条,批量订阅只接收到了260多条,而且接收到的数量随机

Open hn-lyf opened this issue 1 year ago • 2 comments

评论订阅接收保留消息不全,保留消息里有3000条,批量订阅只接收到了260多条,而且接收到的数量随机

using MQTTnet; using MQTTnet.Client;

namespace ConsoleApp1 { internal class Program { static async Task Main(string[] args) { var mqttFactory = new MqttFactory(); var mqttClient = mqttFactory.CreateMqttClient();

        var mqttClientOptions = new MqttClientOptionsBuilder()
          .WithTcpServer("172.16.23.17", 65183)
          .WithClientId("1").WithKeepAlivePeriod(TimeSpan.FromSeconds(10)).WithCredentials("qcxt", "qcxt.comA1+").WithProtocolVersion(MQTTnet.Formatter.MqttProtocolVersion.V500)
          .Build();

        await mqttClient.ConnectAsync(mqttClientOptions);
        for (int i = 0; i < 3000; i++)
        {
            await mqttClient.PublishStringAsync($"sys/dev/{i}/test", Guid.NewGuid().ToString(), qualityOfServiceLevel: MQTTnet.Protocol.MqttQualityOfServiceLevel.AtLeastOnce, retain: true);
        }
        mqttClient.ApplicationMessageReceivedAsync += MqttClient_ApplicationMessageReceivedAsync;
        mqttClient.SubscribeAsync($"sys/dev/+/test", MQTTnet.Protocol.MqttQualityOfServiceLevel.AtLeastOnce);
        Console.WriteLine("Hello, World!");
        Task.Run(async () =>
        {
            while (true)
            {
                Console.WriteLine($"{DateTime.Now} {count} 个");
                await Task.Delay(1000);
            }
        });
        Console.ReadLine();
    }
    static int count = 0;
    private static Task MqttClient_ApplicationMessageReceivedAsync(MqttApplicationMessageReceivedEventArgs arg)
    {
        Console.WriteLine(arg.ApplicationMessage.Topic);
        Task.Run(() =>
        {
            ;
            Console.WriteLine($"Received {Interlocked.Increment(ref count)} 个");
        });
        return Task.CompletedTask;
    }
}

} 只接收到了260多条

hn-lyf avatar Nov 27 '23 11:11 hn-lyf

Heading: Comment subscription receives incomplete retention messages, there are 3000 messages in the retention messages, bulk subscription receives only 260 or so, and the number of messages received is randomized

SeppPenner avatar Nov 27 '23 21:11 SeppPenner

Which broker do you use?

chkr1011 avatar Dec 02 '23 09:12 chkr1011