Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » Paho MQTT Python client: get all messages and disconnect
Paho MQTT Python client: get all messages and disconnect [message #1861894] Fri, 10 November 2023 22:55
Mi Van is currently offline Mi VanFriend
Messages: 2
Registered: February 2023
Junior Member
Using the Paho client I want to get all messages in a given topic and disconnect from the broker.

I can easily do this using simple() as shown here, yet only if I specify the message count using msg_count. This would be fine if the message count were predictable or if there was a means to count the messages in a given topic.
    import paho.mqtt.subscribe as mqtt_subscribe
    messages = mqtt_subscribe.simple('proxies/#', msg_count=4, hostname='mqtt.somewhere.io')
    for m in messages:
     print(m.payload.decode())

I'm also able to get all the messages in my topic using the example shown in Getting Started. However, this uses a loop_forever() and I simply want to get all messages and disconnect. I've tried other loop*() functions, yet none are offering the results I'm seeking.

The Callback Example also returns all messages yet it isn't clear to me how to disconnect from this.

And lastly, I can also use the mosquitto_sub client with a timeout to get all messages: mosquitto_sub -h mqtt.somewhere.io -t "proxies/#" -W 1 but I'd prefer to be consistent with the paho client and better understand it.

[Updated on: Fri, 10 November 2023 22:56]

Report message to a moderator

Previous Topic:How to include MQTT5 into jar (got class not found exception)
Next Topic:Intermittent hang in Paho client when application is connecting.
Goto Forum:
  


Current Time: Fri May 03 13:51:26 GMT 2024

Powered by FUDForum. Page generated in 0.03002 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top