-
Notifications
You must be signed in to change notification settings - Fork 17
Description
🐛 Bug Report
There will be no exception when the Mqtt client is disconnected from the network. When I use HiveMQClient to connect to the Mqtt server, I disconnect the network of the Mqtt server or shut down the mqtt server. At this time, my HiveMQClient will not actively throw any exceptions or information. Including when I try to subscribe to the OnDisconnectReceived event of HiveMQClient, it will not be triggered. Even if I restore the Mqtt server, HiveMQClient will reconnect, but the OnDisconnectReceived event will never be triggered.
I hope that when there is a problem with the network and it cannot connect to Mqtt, there should be an event prompt or an exception thrown, so that my program can actively handle such events. I don't know what you think of this suggestion
🔬 How To Reproduce
Steps to reproduce the behavior:
- ...
Code sample
public static class Test
{
public static async void main()
{
var options = new HiveMQClientOptionsBuilder()
.WithBroker(ip address)
.WithPort(8883)
.WithClientId($"{DateTime.Now.Ticks}")
.WithAutomaticReconnect(true)
.WithUseTls(true)
.WithAllowInvalidBrokerCertificates(true)
.Build();
var client = new HiveMQClient(options);
var connectResult = client.ConnectAsync().ConfigureAwait(false).GetAwaiter().GetResult();
if (connectResult.ReasonCode != ConnAckReasonCode.Success)
{
throw new Exception("Mqtt Server Connect Failed");
}
client.OnDisconnectReceived += clientOnDisconnectReceived;
client.OnDisconnectSent += OnDisconnectSent;
await WaitNoStop();
}
private static void OnDisconnectSent(object? sender, OnDisconnectSentEventArgs e)
{
Console.WriteLine("---Disconnect event 2----");
}
private static void clientOnDisconnectReceived(object? sender, OnDisconnectReceivedEventArgs e)
{
Console.WriteLine("---Disconnect event 1----");
}
public static async Task WaitNoStop()
{
while (true)
{
Thread.Sleep(3000); // 休眠1秒
Console.WriteLine("------------");
}
}