support client_id
Closed this issue · 9 comments
it would be helpful to see the client_id...
The underlying python module seems to support that.
// The client() object creates an MQTT client. It takes 4 parameters which are optional:
client(client_id="", clean_session=True, userdata=None, protocol=MQTTv311, transport="tcp")
Sure, I'll have a look
It seems by default there is no client_id generated. See here
if client_id == "" or client_id is None:
if protocol == MQTTv31:
self._client_id = base62(uuid.uuid4().int, padding=22)
else:
self._client_id = b""
Also, I did not find a clean way to get the client id, as it is a private attribute of client object.
Do you need to have the client id auto generated, or do you want to specify it manually?
I would specify it manually using an ENV variable... if the variable is not present the client_id can be auto generated
ok, I'll add the possibility to specify the client id, and I'll expose it in the metrics if existing.
If the variable is not present the client_id can be auto generated
According the documentation, when client-id is empty, this is up to the MQTT broker to generate it. But the broker does not seem to send back the client-id to the client. In debug mode, client._client_id remains empty even during message processing.
If I force the client-id auto generation on client side, I would have to handle all possible issues such as client id already used.
Yes just leave the id empty and let the server auto generate something...
But the broker does not seem to send back the client-id to the client.
Confirmed here: eclipse-paho/paho.mqtt.python#237 (comment) :
No, if the server generate the clientid then it is not send to client.`
It looks like the behavior is fixed in MQTT v5: eclipse-paho/paho.mqtt.python#237 (comment)
But default protocol in python MQTT client library is MQTT3.1.1.
I'll try with an option to choose the MQTT 5 version. If it is working, we will be able to get back the id generated by the broker and to expose it in Prometheus.
would it work for you? #26.
Feel free to test.
I still need to add some functional tests before merging it.
looks good
Code merged