我正在尝试使用RabbitMQ作为代理发送MQTT消息。我编写了下面的代码并尝试运行它。我能够在RabbitMQ仪表板中看到MQTT队列,但没有消息。没有收到消息,只有队列正在Rabbit中显示:/有什么建议吗?
这是它的样子:
和这个
代码:
using System;
using System.Text;
using System.Net;
using uPLibrary.Networking.M2Mqtt;
using uPLibrary.Networking.M2Mqtt.Messages;
using System.Threading;
namespace MQTTcl
{
class Program
{
public static void Main()
{
// create client instance
MqttClient client = new MqttClient(IPAddress.Parse("127.0.0.1"));
// register to message received
client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;
string clientId = Guid.NewGuid().ToString();
client.Connect(clientId);
// subscribe to the topic "/home/temperature" with QoS 1
client.Subscribe(new string[] { "Xhindi" }, new byte[] { MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE });
string strValue = Convert.ToString("This is a test message by Xhino!!!");
string strValue1 = Convert.ToString("This is a test message by Sandri!!!");
string strValue2 = Convert.ToString("KNP!!!");
string strValue3 = Convert.ToString("KONTH!!!");
System.Threading.Timer timer = null;
timer = new System.Threading.Timer((obj) =>
{
// publish a message on "/home/temperature" topic with QoS 1
client.Publish("Xhindi", Encoding.UTF8.GetBytes(strValue), MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE, false);
// client.Publish("Xhindi", Encoding.UTF8.GetBytes(strValue1), MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE, false);
// client.Publish("Xhindi", Encoding.UTF8.GetBytes(strValue2), MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE, false);
// client.Publish("Xhindi", Encoding.UTF8.GetBytes(strValue3), MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE, false);
// timer.Dispose();
},
null, 15000, System.Threading.Timeout.Infinite);
int milliseconds = 5000;
Thread.Sleep(milliseconds);
//LoadJson();
//writeJson();
}}}