I am working on an IoT application and using C# events to subscribe to MQTT messages. I am using a library that raises an event when a message is received. I have written an Asynchronous EventHandler for processing the message.
The rate at which the messages are being received is higher than the rate of processing them. In this case, I see a delay in the processing of messages, even though the EventHandler is asynchronous.
My question is does C# internally maintain some queue for EventHandlers? If, so can I access that queue for diagnostics purposes? By accessing that queue, I can analyze the exact load which causes the delay.
EDIT
Following is my setup,
- I have .NET Framework 4.6.2 console application.
- In the application I use MQTTnet library for subscribing to MQTT messages.
- Following is the code I use for subscribing,
var mqttFactory = new MqttFactory();
var client = mqttFactory.CreateMqttClient();
client.ApplicationMessageReceivedAsync += async e =>
{
// Process the message. Ex: Update database
}
var clientOptions = mqttFactory.CreateClientOptionsBuilder()
.WithTcpServer("mqtt-broker-host", 9000)
.Build();
await client.ConnectAsync(clientOptions);
await client.SubscribeAsync("mqtt-topic");
- In the handler I process the message. The main part of processing is updating the records in the database.