MQTTnet
MQTTnet copied to clipboard
Adding a user property causes message to not be received by the server
I have an MQTT Net server in asp net framework v 4.7.2. Im using MqttNet v 4.3.1.873 on my server.
MqttServerOptionsBuilder optionsBuilder = new MqttServerOptionsBuilder()
.WithConnectionBacklog( 100 )
.WithDefaultEndpoint()
.WithDefaultEndpointPort(portNumber)
.WithPersistentSessions();
Logger testLogger = new Logger();
var mqttServer = new MqttFactory().CreateMqttServer(optionsBuilder.Build(), testLogger);
await mqttServer.StartAsync( );
If I connect to this server from . Net Core 6 application using the Managed Client, I can send messages. Everything works fine. But When I add a user property, then there are no logs or anything on the server:
This is how i start my client:
MqttClientOptions? mqttClientOptions = new MqttClientOptionsBuilder()
.WithClientId( username )
.WithTcpServer( host, int.Parse( port ) )
.WithCredentials( username, password )
.Build();
ManagedMqttClientOptions? mqttManagedClientOptions = new ManagedMqttClientOptionsBuilder()
.WithAutoReconnectDelay( TimeSpan.FromSeconds( 3 ) )
.WithClientOptions( mqttClientOptions )
.Build();
await _mqttClient.StartAsync( mqttManagedClientOptions );
And this is how i send a message:
MqttApplicationMessageBuilder messageBuilder = new MqttApplicationMessageBuilder()
.WithTopic( channelName )
.WithPayload( payload )
.WithRetainFlag();
messageBuilder.WithUserProperty( "test", "test" );
MqttApplicationMessage message = messageBuilder.Build();
ManagedMqttApplicationMessage managedMqttApplicationMessage = new()
{ ApplicationMessage = message };
await _mqttClient.EnqueueAsync( managedMqttApplicationMessage );
Why does adding a user property cause my message to not reach the server?
User properties require protocol version 5.0.0 to be used. You can set it at the client options. Usually the library will throw an exception when not supported features are used but the managed client seems to catch them.