How to use the gmqtt.Message function in gmqtt

To help you get started, we’ve selected a few gmqtt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wialon / gmqtt / tests / test_mqtt5.py View on Github external
async def test_will_message(init_clients):
    aclient, callback, bclient, callback2 = init_clients

    # re-initialize aclient with will message
    will_message = gmqtt.Message(TOPICS[2], "I'm dead finally")
    aclient = gmqtt.Client(PREFIX + "myclientid3", clean_session=True, will_message=will_message)
    aclient.set_auth_credentials(username)

    await aclient.connect(host, port=port)

    await bclient.connect(host=host, port=port)
    bclient.subscribe(TOPICS[2])

    await asyncio.sleep(1)
    await aclient.disconnect(reason_code=4)
    await asyncio.sleep(1)
    assert len(callback2.messages) == 1
github wialon / gmqtt / examples / properties.py View on Github external
pub_client = gmqtt.Client("clientgonnapub")

    assign_callbacks_to_client(pub_client)
    pub_client.set_auth_credentials(token, None)
    await pub_client.connect(broker_host, broker_port)

    # this message received by sub_client will have two subscription identifiers
    pub_client.publish('TEST/PROPS/42', '42 is the answer', qos=1, content_type='utf-8',
                       message_expiry_interval=60, user_property=('time', str(time.time())))

    pub_client.publish('TEST', 'Test 42', qos=1, content_type='utf-8',
                       message_expiry_interval=60, user_property=('time', str(time.time())))

    # just another way to publish same message
    msg = gmqtt.Message('TEST/PROPS/42', '42 is the answer', qos=1, content_type='utf-8',
                        message_expiry_interval=60, user_property=('time', str(time.time())))
    pub_client.publish(msg)

    pub_client.publish('TEST/42', {42: 'is the answer'}, qos=1, content_type='json',
                       message_expiry_interval=60, user_property=('time', str(time.time())))

    await STOP.wait()
    await pub_client.disconnect()
    await sub_client.disconnect(session_expiry_interval=0)