Exemplo n.º 1
0
        /// <summary>
        /// Response模式,会自动路由到Controler
        /// </summary>
        public void ThreadMQResponse()
        {
            try
            {
                using (ResponseSocket responseSocket = new ResponseSocket())
                {
                    responseSocket.Bind(MQConfig.ResponseServer);

                    while (!_cancellationTokenSource.IsCancellationRequested)
                    {
                        try
                        {
                            IdKeyData receiveData = responseSocket.ResponseReceive();

                            // request模式也需要异步处理,因为有很多个系统用户,会产生并发
                            Task.Factory.StartNew(() =>
                            {
                                string result = RouteConfig.Instance.ExecCmd(receiveData.Id, receiveData.Key, receiveData.Data);
                                responseSocket.ResonseSend(result);
                            });
                        }
                        catch (TerminatingException)
                        {
                        }
                        catch (Exception ex)
                        {
                            MQThreadExceptionHandler?.Invoke(ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MQThreadExceptionHandler?.Invoke(ex);
            }
        }