18

In my understanding, in MQTT a topic is created once a client publishes something with the corresponding topic name.

There is no need to configure a topic, publishing on it is enough.

From here.

It is possible for a client to subscribe to its own topic, after it published, created it? I could not find any restrictions on it in the specifications. It is not listed as possible abnormal behaviour neither:

5.4.8 Detecting abnormal behaviors

Server implementations might monitor Client behavior to detect potential security incidents. For example:

  • Repeated connection attempts
  • Repeated authentication attempts
  • Abnormal termination of connections
  • Topic scanning (attempts to send or subscribe to many topics)
  • Sending undeliverable messages (no subscribers to the topics)
  • Clients that connect but do not send data

Based on this, I think it is certainly possible. So I am interested in what are the uses cases of this feature?

Why does the standard allow such mechanism, would it be to complicated to track the owner of the topics? So instead it just simply allows clients to subscribe to their own topic.

One use case I can think of is that this way a client can verify its published data.

18

Yes, it is possible to subscribe to a topic that is created by itself.

An MQTT client can be both a publisher & subscriber at the same time. In MQTT terms, a client includes both subscribers and publishers.

I am interested in what are the uses cases of this feature?

A possible use case (I assume) is that, suppose if there are three clients (x,y,z) subscribed to a topic x-topic created by x. Whenever a message is published on x-topic, everyone subscribed to that topic will receive the message. If y publishes a message to a topic x-topic (I presume that can be done), if x doesn't subscribe to that topic even though it created the topic, it won't receive the messages.

So a client needs to be subscribed to a topic to receive messages even though this is the original creator of that topic.

But the mechanism can be controlled by using brokers as a medium.

  • Yes, this option crossed my mind. Only, I was not sure if a new client can publish to an existing topic, already used by other publisher. – Bence Kaulics Dec 12 '16 at 9:52
  • Yes, a new client can publish to an existing topic. Remember that clients don't directly communicate, every publication and subscription happens through a broker. – bravokeyl Dec 12 '16 at 11:57
0

Yes.

MQTT clients are connected to a broker which can be a cloud or some other device.

There is no such thing like creation of topic. They are used as a heading for a message. So if your client has subscribed to a topic and if it publish's something on that topic then the message will be received via the broker to the client again.

Examples of good brokers are Mosquitto for running on devices and CloudMqtt for cloud based Broker

  • 4
    This does not really expand the body of knowledge beyond what the other answer already provided a year ago. You are free to add new answers even to answered questions. However, those answers should offer additional or updated insights into the question or the solution. – Helmar May 28 '18 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.