MQTTnet icon indicating copy to clipboard operation
MQTTnet copied to clipboard

Send/receive processing

Open development25 opened this issue 3 years ago • 2 comments

Describe your question

I have two applications, one that sends data and another that receives and sends it in other topics. All this by mqttnet and mosquitto.

The application that sends data, sends it with a very accelerated flow, that is, it sends a lot of data very fast.

And the other application receives them (is subscribed) and forwards them in other topics at the speed of data arrival, that is, if a lot of data arrives, it will publish them just as fast.

If the application that sends it makes it slow, nothing happens. The problem comes when you send a lot of data and very fast, then the second application cannot process the reception and subsequent sending as fast.

Causing the following: if I leave both applications on and turn off the application that only sends, data will continue to arrive to the application that receives and sends.

Keep in mind that if the application that receives and sends only receives, nothing happens.

Attached the project where you can see this problem.

                              https://github.com/development25/MqttNetTest

Which project is your question related to?

  • Client
  • ManagedClient

development25 avatar Aug 24 '22 10:08 development25

To me the behavior sounds correct. The sender will send messages as fast as it can. These messages are then queued in the broker and forwarded to the receiver. If the receiver is slow the queue will grow up and the receiver will receive queued messages even if the sender is no longer sending them.

chkr1011 avatar Sep 17 '22 09:09 chkr1011

Correct. But the error does not occur when I have an application that only sends and another that only receives, even with a high volume of data.

On the other hand, if the receiving application also re-sends, then the slowing down that you mentioned above occurs. Even with a medium data volume.

Why does slowing down only occur when the receiver receives and forwards and not when it only receives?

** When the receiver forwards, it does so through the same mqttnet Client **

development25 avatar Sep 19 '22 07:09 development25

I assume it gets slower because sending is done in the receive handler. To receiving is blocked as long as the message is being forwarded. Depending on connection speed, QoS level and broker performance this might take a while. Things like serialization of the outgoing message and event handlers will also called in the receiver task.

chkr1011 avatar Sep 25 '22 08:09 chkr1011

Exact. Forwarding is done in the receiving controller. But I need that as soon as the data arrives and do some operations, send it and I have not found a way to do it that is not from the reception controller.

Is there a way to prevent the reception from being blocked? Use another mqttnet client (one to send and one to receive) or fire an event when the data reception is finished (that is, when this 'Client.ApplicationMessageReceivedAsync -= MessageReceived' method finishes) or create a client/consumer queue.

Thanks for the help.

development25 avatar Sep 26 '22 07:09 development25

I recommend keeping an external queue which is fed from a receiving client. Another sending client should monitor the queue and send the data as soon as there is any.

chkr1011 avatar Nov 09 '22 19:11 chkr1011

Hi, I'm development25 with my other account.

Thanks, you can close the issue.

cosme-mp avatar Nov 10 '22 07:11 cosme-mp