Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] C++ get_client_id()

The Client ID of the publisher is not carried along with the message to the subscriber. Typically in a loosely-coupled architecture, you don't worry about who sent the message, but rather what the message is referring to. With MQTT this is done by creating a hierarchy of message topics, and specific publishers can send messages to specific topic.

For example, if you place temperature sensors around the house, you can create topics like:
The sensor in the kitchen would publish to the topic "data/temperature/kitchen" and all subscribers could infer that messages on that topic came from the kitchen sensor. Of course, the benefit of this is that different subscribers could choose which messages they want to receive by subscribing to individual rooms, or they could ask to get all the temperature readings by subscribing to a wildcard, like "data/temperature/#". Of course, the topic is sent to the subscriber along with each message, even when subscribed with a wildcard.

But if you really want the Client ID of the sender, you could always add it to the playload of all your messages. But that might not be the greatest idea because it will tie the specific senders and receivers together a bit too tightly.


On 07/05/2017 12:11 AM, Haider Ali wrote:
Hi all,

I am using the mqtt C++ client and looking at async_subscribe.cpp sample. Is there a way to get the client ID using get_client_id() inside the message_arrived function? I need this in my scenario where I have multiple clients subscribing to a topic and I need to perform different tasks based on which client sent the message.

Any other way to approach this problem?

Haider Ali

paho-dev mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit

Back to the top