MQTTnet
MQTTnet copied to clipboard
WithNoLocal(true) fails to suppress receipt of message
Describe the bug
WithNoLocal(true) fails to suppress receipt of message a message published by the same client.
Which project is your bug related to?
- ManagedClient
To Reproduce
Steps to reproduce the behavior:
- Using this version of MQTTnet 3.0.15
- Run this code against current Mosquitto, either a local instance unauthenticated or running on another computer configured using the default password file remembering to uncomment the WithCredentials line.
using System;
using System.Threading;
using MQTTnet;
using MQTTnet.Client.Options;
using MQTTnet.Client.Receiving;
using MQTTnet.Extensions.ManagedClient;
using MQTTnet.Formatter;
namespace MockApp
{
class Program
{
static string ClientId = $"MockApp2_{DateTime.Now.Ticks}";
static void Main(string[] args)
{
// Setup and start a managed MQTT client.
var options = new ManagedMqttClientOptionsBuilder()
.WithAutoReconnectDelay(TimeSpan.FromSeconds(5))
.WithClientOptions(new MqttClientOptionsBuilder()
.WithProtocolVersion(MqttProtocolVersion.V500)
.WithClientId(ClientId)
.WithTcpServer("localhost")
// .WithCredentials("roger", "password")
.Build())
.Build();
var mqttClient = new MqttFactory().CreateManagedMqttClient();
mqttClient.ApplicationMessageReceivedHandler = new MqttApplicationMessageReceivedHandlerDelegate(mre =>
{
var payload = mre.ApplicationMessage.ConvertPayloadToString();
Console.WriteLine($"RECV {payload}");
});
mqttClient.StartAsync(options).Wait();
var arbitraryTopicName = "wibble";
mqttClient.SubscribeAsync(new MqttTopicFilterBuilder()
.WithTopic(arbitraryTopicName)
.WithNoLocal(true)
.Build());
Thread.Sleep(300);
mqttClient.PublishAsync(arbitraryTopicName, "This should not be seen by ApplicationMessageReceivedHandler");
Console.WriteLine(ClientId);
Console.ReadKey();
}
}
}
- Local message is received.
Expected behavior
.WithNoLocal(true) should suppress receipt of the message.
Screenshots

I faced the same problem
This issue still exists in v3.0.16.
This will be fixed in the next version 3.1.0. It supports more MQTTv5 features.
I face the same problem with version 3.1.2 when sending many messages. Because of how my app works i have to publish about 1000 messages when establishing the connection. With a test program I was able to reproduce this problem at about 250 messages.
Before I switched to the ManagedClient I was using the normal Client and it didn't have this issue.
Weirdly the problem doesn't persist when setting NoLocal=true in a SubscriptionInterceptor.
Hi, we have same issue with the ManagedClient and version 3.1.2 even with single messages.
@ChilliPommes @Luki936 The Managed Client does not store this value internally so it can't work with the managed client right now. It only stores the topic and the QoS. I will have a look after 4.0 is released. But anyone is welcome to create a PR which stores the entire topic filter in the ManagedClient instead of the topic and QoS only.
The latest verion 4.0.2 now stores the entire topic filter so that "NoLocal" is also properly sent to the broker.