Hi
I am using MQTT client to send data on RabbitMQ server.
Publisher Code:
static void Main(string[] args)
{
MqttClient client = new MqttClient("104.43.213.30");
byte conn = client.Connect("8", "admin", "admin", false, 9999);
string[] topic = { "World" };
byte[] qoslevels = { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE };
ushort sub = client.Subscribe(topic, qoslevels);
client.ConnectionClosed += new MqttClient.ConnectionClosedEventHandler(client_ConnectionLost);
client.MqttMsgSubscribed += new MqttClient.MqttMsgSubscribedEventHandler(client_MqttMsgSubscribed);
//client.MqttMsgPublished += new MqttClient.MqttMsgPublishedEventHandler(client_MqttMsgPublished);
//client.MqttMsgPublishReceived += new MqttClient.MqttMsgPublishEventHandler(client_PublishArrived);
for (int i = 0; i < 10; i++)
{
ushort t = client.Publish("TestTopic", Encoding.UTF8.GetBytes("testmessage" + i), MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE, false);
Console.WriteLine("Sending: " + "testmessage" + i);
}
Console.ReadLine();
}
Question 1: I subscribe topic(World) but at the time of publish i am sending data to other topic(TestTopic) is it possible to send data to other topic (which is not subscribed).
Question 2: When i create a new project for receiver/subscriber i register topic Test2 but when i ran the code it also receiving the message from other Topic.
Subscriber Code
static void Main(string[] args)
{
MqttClient client = new MqttClient("104.43.213.30");
client.Connect("9", "admin", "admin", false, 9999);
string[] topic = { "Test2" };
byte[] qoslevels = { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE };
ushort sub = client.Subscribe(topic, qoslevels);
client.MqttMsgPublishReceived += new MqttClient.MqttMsgPublishEventHandler(client_PublishArrived);
Console.WriteLine("Waiting to receive messages !!");
Console.ReadLine();
}
private static void client_PublishArrived(object sender, MqttMsgPublishEventArgs e)
{
Console.WriteLine("Message Received");
Console.WriteLine(e.Topic);
Console.WriteLine(Encoding.UTF8.GetString(e.Message));
Console.WriteLine("Quality of service : " + e.QosLevel);
}
Question 3: Is it possible to create a subscriber/publisher which send/read message to a specific topic.
Question 4: Is it possible;e to retain message on Topic after read by subscriber.
Please share the solution of these questions its very urgent for my project.
Thanks
Shreyansh