You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Due to that I don't know if these are bugs or features I make an issue as well out of this.
Added in Q&A as well!
I'm working on a "system controller"/console application that shall monitor and control a few control units (ESP32 based; but not active in these scenarios described here; this is just in the "test" environment in Windows 11) via MQTT.
Connecting to a cloud based (right now ...) broker/server (tried both HiveMQ and emqx variants).
In the application I have, as of right now, three client instances contained in separate own developed "client handlers" that add some extra functionality on top of the MQTTnet client.
I'm adding two event functions to all three of these clients for handling incoming MQTT messages/topics.
The code looks like this:
And _mqttClient is created via your framework as:
_mqttClient = factory.CreateMqttClient();
if (_firstConnect)
{
// What happens if the same message function is added more than ones ???
_mqttClient.ApplicationMessageReceivedAsync -= LogReceivedMessages;
_mqttClient.ApplicationMessageReceivedAsync += LogReceivedMessages;
if (receivedMessageEvent != null)
{
_mqttClient.ApplicationMessageReceivedAsync -= receivedMessageEvent;
_mqttClient.ApplicationMessageReceivedAsync += receivedMessageEvent;
}
// => The method/function is triggered more than ones !!!
// => First always remove the function and then add it you don't get this behavior!
_firstConnect = false;
}
It's "in development" so I have both a check if there are "first connect" if doing the connect for the first time and both removing and adding the two functions (first LogReceivedMessages and second receivedMessageEvent here!) as of now (what is best I also do not know ..).
The log function looks like this:
private async Task LogReceivedMessages(MqttApplicationMessageReceivedEventArgs e)
{
if (LogMessages)
{
Log($"---> Received message ...");
// Log($"From ClientId: {e.ClientId}"); // TODO: Can you get what client that sent the message ???
Log($"Topic received: {e.ApplicationMessage.Topic}");
Log($"Payload/message received: {e.ApplicationMessage.ConvertPayloadToString()}");
// TODO: How get whole message content by default ???
// Log($"Event args: {e.ToString}");
// Log($"Event args: {e.}");
}
}
and is for being able to log incoming messages if that is activated.
The second looks like this and is added as reference via the "receivedMessageEvent" function variable:
private async Task ReceivedMQTTMessageEventStoreLocalCom(MqttApplicationMessageReceivedEventArgs args)
{
// Handle messages from local broker
throw new NotImplementedException("ReceivedMQTTMessageEventStoreLocalCom");
}
So this one throws an exception, important to notice!
Now to the questions and possible bugs:
The exception do not show up in the the console application windows but can be seen in the Visual Studio 2022 window for the debug output. Why?
If I change the order of how the events are added (so instead first adding receivedMessageEvent and second LogReceivedMessages) the second, LogReceivedMessages, are not triggered at all. So the first function are triggered which can be seen from the debug output. BUT then the second function, LogReceivedMessages, is skipped/not triggered?
Are this as it should? Or are the try and catch in your implementation wrongly situated!? Unsure how this works in the MQTTnet implementation ...
The text was updated successfully, but these errors were encountered:
Hi all!
Due to that I don't know if these are bugs or features I make an issue as well out of this.
Added in Q&A as well!
I'm working on a "system controller"/console application that shall monitor and control a few control units (ESP32 based; but not active in these scenarios described here; this is just in the "test" environment in Windows 11) via MQTT.
Connecting to a cloud based (right now ...) broker/server (tried both HiveMQ and emqx variants).
In the application I have, as of right now, three client instances contained in separate own developed "client handlers" that add some extra functionality on top of the MQTTnet client.
I'm adding two event functions to all three of these clients for handling incoming MQTT messages/topics.
The code looks like this:
And _mqttClient is created via your framework as:
_mqttClient = factory.CreateMqttClient();
It's "in development" so I have both a check if there are "first connect" if doing the connect for the first time and both removing and adding the two functions (first LogReceivedMessages and second receivedMessageEvent here!) as of now (what is best I also do not know ..).
The log function looks like this:
and is for being able to log incoming messages if that is activated.
The second looks like this and is added as reference via the "receivedMessageEvent" function variable:
So this one throws an exception, important to notice!
Now to the questions and possible bugs:
The exception do not show up in the the console application windows but can be seen in the Visual Studio 2022 window for the debug output. Why?
If I change the order of how the events are added (so instead first adding receivedMessageEvent and second LogReceivedMessages) the second, LogReceivedMessages, are not triggered at all. So the first function are triggered which can be seen from the debug output. BUT then the second function, LogReceivedMessages, is skipped/not triggered?
Are this as it should? Or are the try and catch in your implementation wrongly situated!? Unsure how this works in the MQTTnet implementation ...
The text was updated successfully, but these errors were encountered: