I am trying to send MQTT messages using RabbitMQ as a broker. I wrote the code below and tried to run it. I am able to see the MQTT Queue in the RabbitMQ dashboard, but there is no message. There is no message received, only the queue is being shown in Rabbit :/ Any advice, please?
This is how it looks like:
and this
Code:
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();
}}}