/// <summary>
        /// 使用WebSocket服务端
        /// </summary>
        /// <param name="app"></param>
        /// <returns></returns>
        public static IApplicationBuilder UseWebSocketServer(this IApplicationBuilder app)
        {
            IServiceProvider         serviceProvider         = app.ApplicationServices;
            IHostApplicationLifetime hostApplicationLifetime = serviceProvider.GetService <IHostApplicationLifetime>();
            WebSocketServerOptions   option = serviceProvider.GetService <IOptions <WebSocketServerOptions> >().Value;
            ILogger         logger          = serviceProvider.GetService <ILoggerFactory>().CreateLogger(typeof(WebSocketServerExtentions));
            WebSocketServer webSocketServer = serviceProvider.GetService <WebSocketServer>();

            app.UseWebSockets();

            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

            hostApplicationLifetime.ApplicationStopping.Register(() => cancellationTokenSource.Cancel());
            app.Use(async(context, next) =>
            {
                if (context.WebSockets.IsWebSocketRequest)
                {
                    using WebSocket webSocket      = await context.WebSockets.AcceptWebSocketAsync();
                    WebSocketConnection connection = new WebSocketConnection(
                        webSocketServer, webSocket, Guid.NewGuid().ToString(), serviceProvider);
                    webSocketServer.AddConnection(connection);
                    if (option.OnConnected != null)
                    {
                        await option.OnConnected(serviceProvider, connection);
                    }
                    logger.LogInformation("收到新的连接 当前连接数:{Count}", webSocketServer.ConnectionCount);

                    List <byte> bytes = new List <byte>();
                    try
                    {
                        while (true)
                        {
                            var buffer = new byte[1024];
                            WebSocketReceiveResult result = await webSocket.ReceiveAsync(new ArraySegment <byte>(buffer), cancellationTokenSource.Token);
                            if (result.CloseStatus.HasValue)
                            {
                                await webSocket.CloseAsync(result.CloseStatus.Value, result.CloseStatusDescription, CancellationToken.None);

                                break;
                            }

                            bytes.AddRange(new ArraySegment <byte>(buffer, 0, result.Count));
                            if (result.EndOfMessage)
                            {
                                //接收数据结束
                                var body = Encoding.UTF8.GetString(bytes.ToArray());

                                //使用内部总线转发,异步处理
                                await _busControl.Publish(new MessageReceivedEvent
                                {
                                    ConnectionId = connection.Id,
                                    Body         = body
                                });
                                bytes.Clear();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex is WebSocketException webSocketException && webSocketException.WebSocketErrorCode == WebSocketError.ConnectionClosedPrematurely)
                        {
                            //忽略
                        }
                        else
                        {
                            logger.LogError(ex, ex.Message);
                        }
                    }
                    finally
                    {
                        webSocketServer.RemoveConnection(connection);
                        logger.LogInformation("连接关闭[{ConnectionId}] 当前连接数:{Count}", connection.Id, webSocketServer.ConnectionCount);
                    }
                }