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

client.OnConnectionLost有时候不会重连? #3

Open
WelcomeAngel opened this issue Aug 25, 2021 · 2 comments
Open

client.OnConnectionLost有时候不会重连? #3

WelcomeAngel opened this issue Aug 25, 2021 · 2 comments

Comments

@WelcomeAngel
Copy link

while (mqClient.IsConnected == false)
{
await mqClient.ReConnectAsync();
Log4NetUtil.Info("ReConnectAsync", new Dictionary<string, object>
{
{ "ConnectResult",connectResult},
{ "mqClientIsConnected", mqClient.IsConnected }
});
}
在里面加了日志没有打印出来
怀疑mqClient.IsConnected还是true,
但定时30秒client.SendMessageAsync返回是Disconnected了
后面改成do while,只打印出了OnConnectionLost,mqClientIsConnected:False ,里面ReConnectAsync还是没有打印出来,ReConnectAsync会卡死了?

            client.OnConnectionLost += async (sender) =>
            {
                var mqClient = sender as MqttClient;

                Log4NetUtil.Info("OnConnectionLost", new Dictionary<string, object> { { "mqClientIsConnected", mqClient.IsConnected }});

                ConnectError connectResult = ConnectError.NotAuthorized;

                do
                {
                    try
                    {
                        connectResult = await mqClient.ReConnectAsync();

                        Log4NetUtil.Info("ReConnectAsync", new Dictionary<string, object>
                        {
                            { "ConnectResult",connectResult},
                            { "mqClientIsConnected", mqClient.IsConnected }
                        });

                        await mqClient.SubscribeAsync(subTopic, MqttQoS.AtMostOnce);

                        Log4NetUtil.Info("SubscribeAsync", new Dictionary<string, object> { });
                    }
                    catch (Exception ex)
                    {
                        Log4NetUtil.Error("ReConnectAsync", new Dictionary<string, object> { { "ex", ex.ToString() } });
                    }
                    await Task.Delay(5000);
                } while (!mqClient.IsConnected && connectResult != ConnectError.ConnectionAccepted);
            };
@xljiulang
Copy link
Owner

这个项目太老不维护了,推荐https://github.com/chkr1011/MQTTnet

@WelcomeAngel
Copy link
Author

这个项目太老不维护了,推荐https://github.com/chkr1011/MQTTnet

好的,谢谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants