MQTTnet
MQTTnet copied to clipboard
Need indication that client message was sent
I got 3.0.0 to work - yes it required code changes, but works fine. And I am writing in VB.NET.
The one thing I need is an event or callback that happens when an enqueued message for a subscribed client is actually published, meaning upon a receipt of a PUBACK on QOS1, or a PUBCOMP on QOS2. I have added the _logger.Info line below at the end of the SendPendingPacketsAsync function in MqttClientConnection.cs. This is crude and I would rather have something more elegant. The ClientMessageQueueInterceptor doesn't quite do this, since a message can still fail to be delivered after the InterceptClientMessageQueueEnqueueAsync(context) is called. The parameters that I would need are the ClientId and MqttQueuedApplicationMessage? If there is a way to do this already, please let me know as I could not find one. We need to update a SQL database with a timestamp showing when a client actually received a message for a subscribed topic. Thanks for any ideas.
}
_logger.Verbose("Queued application message sent (ClientId: {0}).", ClientId);
_logger.Info("Published to ClientId:{0},Topic:{1}", ClientId, queuedApplicationMessage.ApplicationMessage.Topic);
// TODO:
//Interlocked.Increment(ref _sentPacketsCount);
}
Hi, so you mean basically a new handler for the server? At the moment I see no other chance. There is no event yet which is matching your requirement.
What do you expect for QoS 0? No fired event? I would rather invoke it as well after the message was sent. So you can filter on your own according to QoS.
Best regards Christian
Yes please invoke the handler for all successfully sent messages (an error isn't thrown). For QOS0 there still will be a TCP ACK packet coming back from the Client so you can avoid throwing one of the communication exceptions. If you pass the queuedApplicationMessage along with the ClientID, it will have the QualityOfServiceLevel in it for filtering if necessary.
This is the first time I have had to look at the MqttNet source. It is well written. With version 3.0.0., we are currently able to publish securely to Azure IOT Hub, and I also have a self signed certificate working on a MqttServer. When a certain client subscribes, it retrieves records 1000 at a time from SQL server table, then sends them to the client. If the client ACKs receiving the message, I need to update the record as 'processed' with a timestamp. There could be millions of records that have to be published to the client, so I thought it may be too much for the retained message handler in MqttNet?
Are there keepalive settings that can be adjusted, or does the server just use what the client includes in the connection message?
Thanks for your work on this, it really works well.
Please see event ClientAcknowledgedPublishPacketAsync. This event requires QoS 1 or Qo2 to be used.