MQTTnet
MQTTnet copied to clipboard
My client receive Disconnected when I set mqqtv5 to connect emqx bloker
I did following tests
- mqttx desktop client (use mqttv5) to try the emqx bloker that was ok.
- MQTTNET client
If I remove mqttv5 option(swith to
default ProtocolVersio) , the connect worked fine. If I change bloker to mosquito bloker(use mqttv5), everything is ok. If I use mqttv5 to connect to emqx bloker,I recive Disconnect with reason code ( ProtocolError)
Here is my Code
_mqttClientOptions = new MqttClientOptionsBuilder()
.WithProtocolVersion(MqttProtocolVersion.V500)
.WithCredentials("my_user", "testpsw")
.WithTcpServer("exmq.xxx.cn", 1883).Build();
_client.ApplicationMessageReceivedAsync += ProcessEventAsync;
_client.DisconnectedAsync += DisconnectedAsync;
_ = Task.Run(
async () =>
{
// User proper cancellation and no while(true).
while (true)
{
try
{
// This code will also do the very first connect! So no call to _ConnectAsync_ is required in the first place.
if (await _client.TryPingAsync()) continue;
_logger.LogInformation("Try to connect the blocker");
await _client.ConnectAsync(_mqttClientOptions, CancellationToken.None);
SubscribeHandlers(_abpMqttEventBusOptions.Handlers);
_logger.LogInformation("Connected");
}
catch (Exception e)
{
_logger.LogException(e);
}
finally
{
// Check the connection state every 5 seconds and perform a reconnect if required.
await Task.Delay(TimeSpan.FromSeconds(5));
}
}
});
}
private Task DisconnectedAsync(MqttClientDisconnectedEventArgs arg)
{
_logger.LogError(arg.Exception, $"{arg.Reason.ToString()}({(int) arg.Reason})");
return Task.CompletedTask;
}
2024-01-19 14:25:18[INF][MqttEventBus] - Connected 2024-01-19 14:25:18[ERR][MqttEventBus] - ProtocolError(130)
Do you have access to the EMQX logs and see any errors or something of interest? I tested with the public broker at "broker.emqx.io" and it can connect with protocol version 3.1.1 and also 5.0.0.
Do you have access to the EMQX logs and see any errors or something of interest? I tested with the public broker at "broker.emqx.io" and it can connect with protocol version 3.1.1 and also 5.0.0.
I had the same problem, subscribing to a shared theme, and I got an error sub "$share/service1/online/pub" // ProtocolError sub "online/pub" //succeed