示例#1
0
        /// <summary>
        /// Handles the publish complete, for messages that are undergoing Qos ExactlyOnce processing.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        /// <returns>Boolean value indicating whether the message was successfull processed.</returns>
        private bool HandlePublishRelease(MqttMessage msg)
        {
            MqttPublishReleaseMessage pubRelMsg = (MqttPublishReleaseMessage)msg;
            bool publishSuccess = false;

            MqttPublishMessage pubMsg;

            receivedMessages.TryGetValue(pubRelMsg.VariableHeader.MessageIdentifier, out pubMsg);
            if (pubMsg != null)
            {
                receivedMessages.Remove(pubRelMsg.VariableHeader.MessageIdentifier);

                // send the message for processing to whoever is waiting.
                publishSuccess = publishMessageCallback(pubMsg);

                MqttPublishCompleteMessage compMsg = new MqttPublishCompleteMessage()
                                                     .WithMessageIdentifier(pubMsg.VariableHeader.MessageIdentifier);
                connectionHandler.SendMessage(compMsg);
            }
            else
            {
                // TODO: if we receive a publish release but haven't seen the original publish message, what do we do?!
            }

            return(publishSuccess);
        }
示例#2
0
        /// <summary>
        ///     Handles publish received messages during processing of QOS level 2 (Exactly once) messages.
        /// </summary>
        /// <param name="msg">The publish received message</param>
        /// <returns>true or false, depending on the success of message processing.</returns>
        private bool HandlePublishReceived(MqttMessage msg) {
            var recvMsg = (MqttPublishReceivedMessage) msg;

            // if we've got a matching message, respond with a "ok release it for processing"
            if (publishedMessages.ContainsKey(recvMsg.VariableHeader.MessageIdentifier)) {
                MqttPublishReleaseMessage relMsg = new MqttPublishReleaseMessage()
                    .WithMessageIdentifier(recvMsg.VariableHeader.MessageIdentifier);
                connectionHandler.SendMessage(relMsg);
            }

            return true;
        }
示例#3
0
        public void BasicSerialization()
        {
            var expected = new[]
            {
                (byte)0x60,
                (byte)0x02,
                (byte)0x0,
                (byte)0x4,
            };

            MqttPublishReleaseMessage msg = new MqttPublishReleaseMessage().WithMessageIdentifier(4);
            Console.WriteLine(msg.ToString());

            byte[] actual = MessageSerializationHelper.GetMessageBytes(msg);

            Assert.Equal<int>(expected.Length, actual.Length);
            Assert.Equal<byte>(expected[0], actual[0]); // msg type of header
            Assert.Equal<byte>(expected[1], actual[1]); // remaining length
            Assert.Equal<byte>(expected[2], actual[2]); // connect ack - compression? always empty
            Assert.Equal<byte>(expected[3], actual[3]); // return code.
        }