Rabbit MQ MQTT Client

139 views
Skip to first unread message

shriyansh jain

unread,
May 25, 2015, 9:36:02 AM5/25/15
to rabbitm...@googlegroups.com
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

Michael Klishin

unread,
May 25, 2015, 10:10:54 AM5/25/15
to shriyansh jain, rabbitm...@googlegroups.com
 

On 25 May 2015 at 16:36:05, shriyansh jain (shriya...@gmail.com) wrote:
> 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).

Publishers can publish to any topic but if there are no consumers, they are
discarded.

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

Note that QoS 2 is not supported by RabbitMQ.
 
> Question 3: Is it possible to create a subscriber/publisher
> which send/read message to a specific topic.

Yes, you can publish and subscribe to topics without wildcards.

> Question 4: Is it possible;e to retain message on Topic after
> read by subscriber.

If you mean retained messages as defined in the MQTT spec, their support is coming in 3.6.

If you mean "keep around messages on topics that previously had no QoS1 consumers" then no, this
is not generally possible with MQTT servers. Take a look at Kafka. 
--
MK

Staff Software Engineer, Pivotal/RabbitMQ


Reply all
Reply to author
Forward
0 new messages