21

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.

Bence Kaulics
  • 7,843
  • 8
  • 42
  • 90

2 Answers2

20

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.

Bence Kaulics
  • 7,843
  • 8
  • 42
  • 90
bravokeyl
  • 1,550
  • 1
  • 13
  • 27
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