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); }
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); }