Coder Social home page Coder Social logo

Asynchronous handlers about gmqtt HOT 7 CLOSED

wialon avatar wialon commented on June 25, 2024
Asynchronous handlers

from gmqtt.

Comments (7)

Lenka42 avatar Lenka42 commented on June 25, 2024 3

Hi, @DurandA
It's now possible to use asynchronous on_message callback (yes, only this one at the moment)
I will add comment about this to README in nearest future. You can see example usage here: https://github.com/wialon/gmqtt/blob/master/tests/test_mqtt5.py#L268 The only important thing here: asynchronous callback must return proper PUBACK code which will be used in PUBACK response to broker. So if everything went fine, just return 0. Full list of possible codes is here: https://github.com/wialon/gmqtt/blob/master/gmqtt/mqtt/constants.py#L69

from gmqtt.

DurandA avatar DurandA commented on June 25, 2024 1

After some investigation, the issue is due to iscoroutinefunction() which does not work with functools.partial.

Here is a minimal example:

def on_connect(client, flags, rc, properties):
    client.subscribe('#')

async def on_message(client, topic, payload, qos, properties, loop=None):
    await asyncio.sleep(1, loop=loop)
    return 0

async def init(loop):
    mqtt_client = MQTTClient('') # anonymous
    mqtt_client.on_connect = on_connect
    mqtt_client.on_message = partial(on_message, loop=loop)

from gmqtt.

Lenka42 avatar Lenka42 commented on June 25, 2024 1

@DurandA I released fix for partial coroutines, please check newest version

from gmqtt.

DurandA avatar DurandA commented on June 25, 2024 1

Many thanks!

from gmqtt.

DurandA avatar DurandA commented on June 25, 2024

Awesome, thank you!

from gmqtt.

DurandA avatar DurandA commented on June 25, 2024

@Lenka42 The error is still present when using functools.partial.

from gmqtt.

Lenka42 avatar Lenka42 commented on June 25, 2024

Could you please share minimal peace of code with your on_message handler?

from gmqtt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.