コード例 #1
0
        // 发送数据量大的情况使用DealerSend,否则使用RequestSocket
        private void ThreadDealerSend()
        {
            using (DealerSocket dealerSocket = new DealerSocket())
            {
                dealerSocket.Options.Identity = Encoding.UTF8.GetBytes(PublicData.SessionId);
                dealerSocket.Connect(MQConfig.RouterReceiveServer);

                while (!PublicData.CancellationToken.IsCancellationRequested)
                {
                    try
                    {
                        KeyData item;
                        if (PublicData.DealerSendQueue.TryTake(out item, -1))
                        {
                            dealerSocket.DealerSend(item);
                            MqDealerSendEvent?.Invoke(item);
                        }
                    }
                    catch (TerminatingException ex)
                    {
                        LogUtil.Error($"dealer消息发送异常:{ex.Message}");
                    }
                    catch (Exception ex)
                    {
                        LogUtil.Error($"dealer消息发送异常:{ex.Message}");
                    }
                }
            }
        }