amqtt/samples/broker_start.py

44 wiersze
1.1 KiB
Python
Czysty Zwykły widok Historia

2015-07-07 20:48:53 +00:00
import logging
import asyncio
import os
2015-07-07 20:48:53 +00:00
from hbmqtt.broker import Broker
logger = logging.getLogger(__name__)
2015-08-06 19:08:22 +00:00
config = {
'listeners': {
'default': {
2015-09-30 20:41:18 +00:00
'type': 'tcp',
2015-08-06 19:08:22 +00:00
'bind': '0.0.0.0:1883',
},
'ws-mqtt': {
'bind': '127.0.0.1:8080',
2015-09-30 20:41:18 +00:00
'type': 'ws',
'max_connections': 10,
2015-08-06 19:08:22 +00:00
},
2015-08-08 11:57:48 +00:00
},
2015-10-19 19:37:31 +00:00
'sys_interval': 10,
'auth': {
2015-09-06 20:23:06 +00:00
'allow-anonymous': True,
2015-08-29 20:10:28 +00:00
'password-file': os.path.join(os.path.dirname(os.path.realpath(__file__)), "passwd"),
'plugins': [
'auth_file', 'auth_anonymous'
]
}
2015-08-06 19:08:22 +00:00
}
broker = Broker(config)
2015-07-07 20:48:53 +00:00
async def test_coro():
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())
2015-07-10 20:55:43 +00:00
asyncio.get_event_loop().run_forever()