2
votes

I am new to MQTT and I have some questions that I hope you guys could help me with. I'm working on a school project that will require me to utilize the MQTT protocol and the program needs to be written in C. (Just some background info)

  1. Can a MQTT client be both a publisher and a subscriber at the same time? That is, while constantly waiting to receive messages from the broker and perform resulting actions, it is also able to publish messages to a broker when needed to.

    My understanding of MQTT is as such: MQTT Publisher --> MQTT Broker --> MQTT Subscriber

  2. What exactly is the Asynchronous mode of MQTT, in idiot terms?

Thanks!

2

2 Answers

3
votes

1) Yes, there is no reason a MQTT Client can not be a Published and a Subscriber, this is a normal mode for a client to work in.

2) An Asynchronous MQTT client implementation is one that does not block when carrying out network operations (sending or receiving data). This means that all the network operations take place in the background, a token is returned from any call that would normally block that can be used to check if that operation succeeded later.

1
votes

1) When you say your mqtt client has subscribed to a particular topic it means that It will keep on listening to that till either it is unsubscribed or the connection is Terminated. When you say your mqtt client is publishing, it publishes the MqttMessage to the Broker and all the clients who are subscribed i.e listening will receive the message. So you just need to keep yourself subscribed and start publishing.

2)Asynchronous mode doesn't block the thread for performing any action. It just acts on the given action and returns a token which can be used to track and wait for the action to get completed. This is opposite to Synchronous mode where the Thread is blocked till the action is completed on reached the timeOut period.

Eg: When you publish in Asynchronous mode, you will be returned a IMqttDeliveryToken which can be used later to verify if the publish action was completed.