Ejemplo n.º 1
0
        public void ResponseReceive(int Milliseconds = NetmqOptions.ResopneMillisecond)
        {
            Task.Factory.StartNew((par) =>
            {
                try
                {
                    var listen      = par as List <PublisherListen>;
                    var isCancel    = cancellationTokenSource.Token.IsCancellationRequested;
                    var mqTime      = new NetMQTimer(TimeSpan.FromMilliseconds(Milliseconds));
                    mqTime.Elapsed += (sender, e) =>
                    {
                        if (isCancel)
                        {
                            e.Timer.Enable = false;
                            return;
                        }

                        _netMQManage.ResponseReceive((a) =>
                        {
                            //收到消息后进行回调处理业务,处理完后在 反馈消息出去
                            var request = JsonConvert.DeserializeObject <RequestData>(a);
                            listen.ResultListens(request.Id);
                            return(ResultResponse(request));
                        });
                    };
                    using (var poller = new NetMQPoller {
                        mqTime
                    })
                    {
                        poller.Run();
                    }
                }
                catch (Exception ex)
                {
                    LogWrite.Error(ex);
                }
            }, _publisherListens, cancellationTokenSource.Token);
        }