Ejemplo n.º 1
0
    args = parser.parse_args()

    logging.basicConfig(format='[%(asctime)s] %(levelname).1s - %(message)s',
                        level=logging.DEBUG if args.debug else logging.INFO)
    log.debug("Debug logging level is active")

    with open(args.specification_file, "r") as specification_file:
        specification = load(specification_file, Loader=Loader)

    with open(args.events_file, "r") as events_file:
        events = load(events_file, Loader=Loader)

    channels = [
        os.path.join("/", channel_name)
        for channel_name in specification["channels"].keys()
    ]

    log.info(f"Registered channels: {channels}")

    host = "0.0.0.0"
    server = WebSocketServer((host, args.port),
                             Resource(
                                 OrderedDict([(channel, ChannelApplication)
                                              for channel in channels])))
    server.specification = specification
    server.events = events
    server.valid_command_chain_time = time.time()
    server.args = args
    log.info(f"Started AsyncApi-WebSocket-Mock server at {host}:{args.port}")
    server.serve_forever()