amqtt/samples/client_publish_acl.py

40 wiersze
1.2 KiB
Python
Czysty Zwykły widok Historia

2018-03-19 09:58:56 +00:00
import logging
import asyncio
2021-03-27 12:59:48 +00:00
from amqtt.client import MQTTClient, ConnectException
2018-03-19 09:58:56 +00:00
#
# This sample shows how to publish messages to broker using different QOS
# Debug outputs shows the message flows
#
logger = logging.getLogger(__name__)
2020-12-31 00:16:45 +00:00
async def test_coro():
2018-03-19 09:58:56 +00:00
try:
C = MQTTClient()
await C.connect("mqtt://0.0.0.0:1883")
await C.publish("data/classified", b"TOP SECRET", qos=0x01)
await C.publish("data/memes", b"REAL FUN", qos=0x01)
2021-03-27 12:59:48 +00:00
await C.publish("repositories/amqtt/master", b"NEW STABLE RELEASE", qos=0x01)
await C.publish(
2021-03-27 12:59:48 +00:00
"repositories/amqtt/devel", b"THIS NEEDS TO BE CHECKED", qos=0x01
)
2021-03-27 12:59:48 +00:00
await C.publish("calendar/amqtt/releases", b"NEW RELEASE", qos=0x01)
2018-03-19 09:58:56 +00:00
logger.info("messages published")
2020-12-31 00:16:45 +00:00
await C.disconnect()
2018-03-19 09:58:56 +00:00
except ConnectException as ce:
logger.error("Connection failed: %s" % ce)
asyncio.get_event_loop().stop()
if __name__ == "__main__":
formatter = (
"[%(asctime)s] %(name)s {%(filename)s:%(lineno)d} %(levelname)s - %(message)s"
)
2018-03-19 09:58:56 +00:00
formatter = "%(message)s"
logging.basicConfig(level=logging.DEBUG, format=formatter)
asyncio.get_event_loop().run_until_complete(test_coro())