public void OnMqttMsgSubscribeReceived(MqttClientConnection clientConnection, ushort messageId, string[] topics, byte[] qosLevels) { var wasSubscribed = false; for (var i = 0; i < topics.Length; i++) { if (uacManager.AuthenticateSubscriber(clientConnection, topics[i])) { // TODO : business logic to grant QoS levels based on some conditions ? // now the broker granted the QoS levels requested by client // subscribe client for each topic and QoS level requested MqttSubscriberManager.Subscribe(topics[i], qosLevels[i], clientConnection); wasSubscribed = true; } } if (wasSubscribed) { // send SUBACK message to the client MqttOutgoingMessageManager.Suback(clientConnection, messageId, qosLevels); foreach (var topic in topics) { // publish retained message on the current subscription RetainedMessageManager.PublishRetaind(topic, clientConnection); } } }