amqtt/samples/broker_start.py

48 wiersze
1.1 KiB
Python
Czysty Zwykły widok Historia

2015-07-07 20:48:53 +00:00
import asyncio
import logging
import os
2021-03-27 12:59:48 +00:00
from amqtt.broker import Broker
2015-07-07 20:48:53 +00:00
logger = logging.getLogger(__name__)
2015-08-06 19:08:22 +00:00
config = {
"listeners": {
"default": {
"type": "tcp",
"bind": "0.0.0.0:1883",
2015-08-06 19:08:22 +00:00
},
"ws-mqtt": {
"bind": "127.0.0.1:8080",
"type": "ws",
"max_connections": 10,
2015-08-06 19:08:22 +00:00
},
2015-08-08 11:57:48 +00:00
},
"sys_interval": 10,
"auth": {
"allow-anonymous": True,
"password-file": os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"passwd",
),
"plugins": ["auth_file", "auth_anonymous"],
2019-01-04 17:29:48 +00:00
},
"topic-check": {"enabled": False},
2015-08-06 19:08:22 +00:00
}
broker = Broker(config)
2015-07-07 20:48:53 +00:00
2017-08-06 22:06:57 +00:00
async def test_coro() -> None:
2020-12-31 00:16:45 +00:00
await broker.start()
# await asyncio.sleep(5)
# await broker.shutdown()
2015-07-07 20:48:53 +00:00
if __name__ == "__main__":
2015-09-03 20:20:31 +00:00
formatter = "[%(asctime)s] :: %(levelname)s :: %(name)s :: %(message)s"
# formatter = "%(asctime)s :: %(levelname)s :: %(message)s"
2015-10-15 19:57:21 +00:00
logging.basicConfig(level=logging.INFO, format=formatter)
2015-07-07 20:48:53 +00:00
asyncio.get_event_loop().run_until_complete(test_coro())
2017-08-06 22:06:57 +00:00
asyncio.get_event_loop().run_forever()