/// <summary> /// 添加ACK 信息,供CONSUMER使用 /// </summary> /// <param name="consumerUri"> </param> /// <param name="server"></param> /// <param name="ack"></param> public void AppendAck(string consumerUri,PhysicalServer server,ConsumerAck ack) { Guard.ArgumentNotNull(server, "server"); Guard.ArgumentNotNull(ack, "ack"); Output.AddOrUpdate(server.ServerDomainName, s => { var queue = new ConcurrentQueue<CBox<Tuple<string, ConsumerAck>>>(); queue.Enqueue(new CBox<Tuple<string, ConsumerAck>> { Value = new Tuple<string, ConsumerAck>(consumerUri, ack) }); //定时Ack _timerScheduler.Register(() => { var tmp = server; RunTaskAck(tmp); }, s, _ackIntervalTime, false); //对于新增的SERVER 启动TASK 进行自动ACK return queue; }, (s, d) => { var tmp = server; d.Enqueue(new CBox<Tuple<string, ConsumerAck>> {Value = new Tuple<string, ConsumerAck>(consumerUri, ack)}); if (d.Count >= Consts.Consumer_DefaultAckQueueBoundary) //Queue 数量大于 { System.Threading.ThreadPool.QueueUserWorkItem(RunTaskAck, tmp); } return d; }); }
/// <summary> /// 发送Ack消息 /// </summary> /// <param name="duration"></param> /// <param name="message"></param> private void SendAck(int duration,Message message) { var ack = new ConsumerAck { Duration = duration, MessageID = message.ChunkSubMessage.Pub.MessageID, Position = message.ChunkSubMessage.Position, Timestamp = message.ChunkSubMessage.Timestamp, Acks = message.Acks, Uri = PullingRequestUri }; Buffer.SendAck(message.ChunkSubMessage.ServerHostName, ack); }