Exemplo n.º 1
0
        public MqttMessage Publish(MqttMessage message)
        {
            var success = SometimesFalse();

            if (!success)
            {
                Log.Verbose($"Randomly failing Publish call for {message.GetRawTopic()}: {message.message}");
            }

            if (success)
            {
                message.messageId = _messageId++;

                MessagePublished?.Invoke(message);

                message.messageId = _messageId++;

                /*
                 * Task.Run(() =>
                 * {
                 *  //System.Threading.Thread.Sleep(GetRandom());
                 *  //message.prependDeviceId = false;
                 *  MessageReceivedString?.Invoke(message);
                 * });
                 */

                System.Threading.Thread.Sleep(GetRandom(100));
                MessageReceivedString?.Invoke(message);
            }
            return(message);
        }
Exemplo n.º 2
0
        private void Client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
        {
            var msg = MqttMessageBuilder
                      .NewMessage()
                      .AddTopic(e.Topic)
                      .SetMessage(Encoding.UTF8.GetString(e.Message))
                      .SetRawMessage(e.Message)
                      .SetMessageType(MqttMessageType.MQTT_PUBLISH)
                      .Build();

            MessageReceivedString?.Invoke(msg);
        }