Exemple #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));
        }
Exemple #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);
 }
Exemple #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);
     }
 }
Exemple #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));
 }