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

mosquitto_sub timeout. #275

Closed
HariniJSrowa opened this issue Sep 26, 2016 · 7 comments
Closed

mosquitto_sub timeout. #275

HariniJSrowa opened this issue Sep 26, 2016 · 7 comments
Labels
Component: mosquitto-clients Type: Enhancement A new feature for a minor or major release.
Milestone

Comments

@HariniJSrowa
Copy link

Does mosquitto_sub have the feature of waiting for a response and if it does not get any response it should timeout within a time frame.

@ralight
Copy link
Contributor

ralight commented Sep 28, 2016

No it doesn't. You can specify that it exits after a certain count of messages though. I'm going to leave this open as a possible enhancement.

@ralight ralight added Type: Enhancement A new feature for a minor or major release. Component: mosquitto-clients labels Sep 28, 2016
@HariniJSrowa
Copy link
Author

Thanks Roger ! Well, the test case is with a setup of all three mosquitto_pub, mosquitto_sub and mosquitto broker running on one single machine with either CentOS 6.5/Ubuntu 14.04 LTS. I run mosquitto_pub in a while loop (forever)and keep publishing data on a certain topic and subscribe too (forever)for the same. I terminate mosquitto_pub after some time and that leaves mosquitto_sub hung :(. I want mosquitto_sub to quit or receive some event from broker that there are no more publishers running but mosquitto_sub just keeps sending PINGREQ and receives PINGRESP as per the protocol.

Do you suggest any way for the mosquitto_sub to know that there are no more messages to be received since the publisher itself is not running? In this case it cannot even exit after the count of messages since if I run mosquitto_sub -h 127.0.0.1 -t Test -C 1 it hangs since no publisher is running.

@ralight
Copy link
Contributor

ralight commented Sep 30, 2016

At the moment, no this is not possible. This would be quite trivial for you to implement by writing your own client though.

@HariniJSrowa
Copy link
Author

Yes ! Thanks !

mhei added a commit to chargebyte/mosquitto that referenced this issue Oct 17, 2017
This add a new command line parameter to give a timeout for message
processing. It is implemented using alarm(2) and thus available at
the moment only for POSIX platforms (also because I have no WIN32
build environment at hand).

Signed-off-by: Michael Heimpold <[email protected]>
mhei added a commit to chargebyte/mosquitto that referenced this issue Jan 12, 2018
This add a new command line parameter to give a timeout for message
processing. It is implemented using alarm(2) and thus available at
the moment only for POSIX platforms (also because I have no WIN32
build environment at hand).

Signed-off-by: Michael Heimpold <[email protected]>
@victorclaessen
Copy link

So sorry to resurrect this thread (but it was never closed, it seems). This is a really useful feature. For instance, for checking to see if an 'alive' signal is received within a certain time frame.

I was just wondering, would it be useful to set the exit code of the mosquitto_sub process according to whether there was a message received or not? Perhaps 0 if there was a message, and 1 if the timeout had occurred? (I realise that one could also check stdout to see if it was empty or not.)

@ralight
Copy link
Contributor

ralight commented Sep 4, 2019

The timeout option was added a while back in 1.6. I've just added the option to have a timeout specific exit code, which will be in 1.7.

@ralight ralight added this to the 1.7 milestone Sep 4, 2019
@ralight ralight closed this as completed Sep 4, 2019
ralight added a commit that referenced this issue Sep 4, 2019
@victorclaessen
Copy link

Awesome. Thanks!

@lock lock bot locked as resolved and limited conversation to collaborators Dec 6, 2019
@ralight ralight modified the milestones: 1.7, 2.0 Oct 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Component: mosquitto-clients Type: Enhancement A new feature for a minor or major release.
Projects
None yet
Development

No branches or pull requests

3 participants