コード例 #1
0
        /// <summary>
        /// Router模式,会自动路由到Controler
        /// </summary>
        public void ThreadMQRouterReceive()
        {
            try
            {
                using (RouterSocket routerSocket = new RouterSocket())
                {
                    routerSocket.Bind(MQConfig.RouterReceiveServer);

                    while (!_cancellationTokenSource.IsCancellationRequested)
                    {
                        try
                        {
                            IdKeyData receiveData = routerSocket.RouterReceive();
                            Task.Factory.StartNew(() =>
                            {
                                RouteConfig.Instance.ExecCmd(receiveData.Id, receiveData.Key, receiveData.Data);
                            });
                        }
                        catch (TerminatingException)
                        {
                        }
                        catch (Exception ex)
                        {
                            MQThreadExceptionHandler?.Invoke(ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MQThreadExceptionHandler?.Invoke(ex);
            }
        }