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)); }
/// <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); }
/// <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); } }
/// <summary> /// 生产者发送消息 /// </summary> /// <param name="topic"></param> /// <param name="content"></param> public void Publish(string topic, string content) { _batcher.Insert(_queueCoder.Publish(_name, topic, content)); }