Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any way to check if a subscription is currently active? #1572

Open
dpostorivo opened this issue Feb 5, 2025 · 1 comment
Open
Labels

Comments

@dpostorivo
Copy link
Contributor

More of a question than anything else. Running into an issue where long running subscriptions seem to be being dropped or forgotten inconsistently by the broker I'm using VernMQ. I need some way to find out if the subscription I have as the devices need to act on the incoming messages.

Basic flow of the device's state is CONNECT -> SUBSCRIBE -> IDLE(wait for data) -> SEND -> IDLE(ect.). The subscribe is always directly after the connect and as long as no disconnects or errors are seen it stays in idle and waits for data to send.

I have an idea to send to the topic that is supposed to be described, but if there's a direct way in paho to check if a subscription is still valid that would be more ideal. Is there some functionality in paho I'm missing to help with this?

@icraggs
Copy link
Contributor

icraggs commented Feb 11, 2025

There isn't a formal broker agnostic way to find that out in MQTT as far as I know.

Each client could send a test message to the topic once it has subscribed to see if the message gets back, but anyone else subscribed to that topic would have to know to expect test messages too.

Some brokers have an admin API that allows you to query the state of the broker. Often HTTP and you'd have to have admin access.

I just had a look at MQTT 5. and there is a reason code on unsubscribe ("no subscription existed") so that would be a way, if VerneMQ used that reason code. You'd be unsubscribing in the process though.

Again in MQTT 5 there is a subscribe option to only send retained messages if the subscription did not previously exist. So if you set a retained message on the topic (which some other client could remove when you weren't looking!) and use this option, if the client received a retained message you'd know that the subscription didn't previously exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants