0

I'm trying to use paho.mqtt for python (project pages) and all works nice. The only problem I have is I would find it very useful to find out who had sent the message. I looked up the source code but could not quite get my head around if the client variable passed within on_message is the client I use to connect to or details of the client who published the message (I'm guessing it's the first option).

So the question is - is it possible to find out who (the user name) had sent the message?

Greg0ry
  • 931
  • 8
  • 25

1 Answers1

2

The MQTT protocol was designed to be as light weight as possible, this means that the message header contains the absolute bare minimum to deliver a message to a specific topic. There is no room in the header for anything else.

MQTT is also a Pub/Sub protocol, one of the key features of this type of protocol is to decouple the publisher from the subscriber as much as possible. This means that the publisher shouldn't care how many subscribers there are and subscribers shouldn't care where the information comes from as long as it is to a topic it's interested in.

If you want any more information other than the message topic then you have to add it to the payload yourself.

hardillb
  • 54,545
  • 11
  • 67
  • 105
  • So if I have 10 different publishers (say 10 different customers) it's not possible to find out who had sent what unless they add this to the payload? – Greg0ry Nov 11 '16 at 00:07
  • yes, the other option is that each customer publishes to their own topics (with a common prefix) and the subscribers can use a wild card subscription and use the topic to determine where they came from – hardillb Nov 11 '16 at 00:08