示例#1
0
        public void Publish(string topic, string content)
        {
            while (_concurrentQueue.Count > 10000)
            {
                ThreadHelper.Sleep(1);
            }
            _concurrentQueue.Enqueue(_queueCoder.Publish(_name, topic, content));

            //Send(_queueCoder.Publish(_name, topic, content));
        }
示例#2
0
 /// <summary>
 /// 生产者发送消息
 /// </summary>
 /// <param name="topic"></param>
 /// <param name="content"></param>
 public void Publish(string topic, string content)
 {
     Monitor.Enter(sendLock);
     cache.AddRange(_queueCoder.Publish(_name, topic, content));
     if (cache.Count < 1000 * 10 || _sendSpan < DateTimeHelper.Now)
     {
         Monitor.Exit(sendLock);
         return;
     }
     SendAsync(cache.ToArray());
     cache.Clear();
     _sendSpan = DateTimeHelper.Now.AddMilliseconds(500);
     Monitor.Exit(sendLock);
 }
示例#3
0
 /// <summary>
 /// 生产者发送消息
 /// </summary>
 /// <param name="topic"></param>
 /// <param name="content"></param>
 public void Publish(string topic, string content)
 {
     try
     {
         Monitor.Enter(sendLock);
         cache.AddRange(_queueCoder.Publish(_name, topic, content));
         if (cache.Count < 1000 * 10 || _sendSpan < DateTimeHelper.Now)
         {
             return;
         }
         Send(cache.ToArray());
         cache.Clear();
         _sendSpan = DateTimeHelper.Now.AddMilliseconds(500);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         Monitor.Exit(sendLock);
     }
 }
示例#4
0
 /// <summary>
 /// 生产者发送消息
 /// </summary>
 /// <param name="topic"></param>
 /// <param name="content"></param>
 public void Publish(string topic, string content)
 {
     _batcher.Insert(_queueCoder.Publish(_name, topic, content));
 }