amqtt/samples/broker_start.py

49 wiersze
1.2 KiB
Python
Czysty Zwykły widok Historia

2015-07-07 20:48:53 +00:00
import logging
import asyncio
from hbmqtt.broker import Broker
logger = logging.getLogger(__name__)
2015-08-06 19:08:22 +00:00
config = {
'listeners': {
'default': {
'type': 'tcp'
},
'tcp-mqtt': {
'bind': '0.0.0.0:1883',
},
'ws-mqtt': {
'bind': '127.0.0.1:8080',
'type': 'ws'
},
'wss-mqtt': {
'bind': '127.0.0.1:8081',
'type': 'ws',
'ssl': 'on',
'certfile': 'localhost.server.crt',
'keyfile': 'server.key',
},
'tcp-ssl': {
'bind': '127.0.0.1:8883',
'ssl': 'on',
'certfile': 'localhost.server.crt',
'keyfile': 'server.key',
'type': 'tcp'
}
}
}
broker = Broker(config)
2015-07-07 20:48:53 +00:00
@asyncio.coroutine
def test_coro():
yield from broker.start()
2015-07-10 20:55:43 +00:00
#yield from asyncio.sleep(5)
#yield from broker.shutdown()
2015-07-07 20:48:53 +00:00
if __name__ == '__main__':
formatter = "[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s - %(message)s"
logging.basicConfig(level=logging.DEBUG, format=formatter)
asyncio.get_event_loop().run_until_complete(test_coro())
2015-07-10 20:55:43 +00:00
asyncio.get_event_loop().run_forever()