-
Notifications
You must be signed in to change notification settings - Fork 76
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
Publish should not wait for confirmation #48
Comments
Thanks for opening this issue. Let me have a look. :)
I never considered that use case. Thanks for bringing it to my attention. 👍 Your question in #46 makes a lot more sense to me now. To support this, we need to make some API-breaking changes. I'm up for it, though. Make
|
As long as the |
This is part of the experimental anyio-based branch. See #44. |
Regarding this statement,
Has anything changed in I have no problem with the following code, where I re-use the same client and connect/disconnect every second. class Publisher:
def __init__(
self,
url,
topics
) -> None:
self.url = url
if isinstance(topics, str):
topics = [topics]
self.topics = topics
async def run(self):
i = 0
client = Client(self.url)
while True:
message = f"Message n{i}"
async with client:
for topic in self.topics:
await client.publish(topic, message.encode())
print(client._disconnected.done()) # Returns True
await asyncio.sleep(1)
i += 1
if __name__ == "__main__":
publisher = Publisher(MQTT_BROKER_ADDRESS, "some_topic")
asyncio.get_event_loop().run_until_complete(publisher.run()) |
Hi Robin, thanks for the comment here. :)
For now, It may be that Robin, if you want to, you can make a PR with a suite of tests that proves that |
I don't think this is correct, QoS1 means could make sure that message was sent.It's not reliable to store message in memory, the only way to make sure messages sent is to store it in disk(which is too much work for a mqtt client), and send them one by one, or you MUST accept some message sending may be failed. |
Making |
Curiously asking, why is making it work outside the client context so unexpected, shouldn't a client work like that being connected to the broker, publishes and reads messages when they come, but shouldn't the connection be persistent? |
I might have misphrased, the unexpected part is the suggested behavior.: |
Yes @spacemanspiff2007, got your point, makes good sense to me now what you say. |
The
publish()
method forces the user to wait for the message to be published. It is perfectly reasonable to publish a message with QOS > 0 when the client is disconnected. For example, on unreliable links, a loop in a thread/task is used to reconnect when the connection goes down. The publisher can continue on publishing at QOS > 0 without knowing anything about the status of the connection. This is not possible with the currentpublish()
implementation and puts a bigger implementation burden on the user of this library.The text was updated successfully, but these errors were encountered: