Skip to content

Subscriptions are dropped following reconnect #10

Description

@basak

Hi,

Thank you for trio-paho-mqtt!

Following the pattern in the README.md example, I did something equivalent to:

async with trio.open_nursery() as nursery:
    sync_client = mqtt.Client()
    client = AsyncClient(sync_client, nursery)
    client.connect(...)
    client.subscribe(topic)
    async for message in client.messages():
        ...

However I seemed to stop receiving messages after a while. I think this is because the connection timed out, the (sync) client reconnected automatically, but the subscription wasn't recreated.

https://github.com/eclipse/paho.mqtt.python/blob/master/README.rst says:

# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
    print("Connected with result code "+str(rc))

    # Subscribing in on_connect() means that if we lose the connection and
    # reconnect then subscriptions will be renewed.
    client.subscribe("$SYS/#")

However I can't straightforwardly do this in trio-paho-mqtt because you're already using the sync client on_connect method for internal purposes, and aren't exposing that to the API user.

I wonder if you could provide on_connect functionality directly from AsyncClient please?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions