private bool Add(IMessageId messageId) { try { var partition = TimePartitions.Peek(); if (!MessageIdPartitionMap.TryGetValue(messageId, out var _)) { var added = partition.Add(messageId); MessageIdPartitionMap[messageId] = partition; return(added); } return(partition.Add(messageId)); } catch (Exception ex) { _log.Error(ex.ToString()); return(false); } }
private async ValueTask RedeliverMessages() { var messagesToRedeliver = new HashSet <IMessageId>(); if (TimePartitions.TryDequeue(out var headPartition)) { if (headPartition.Count > 0) { _log.Warning($"[{_consumer.Path.Name}] {headPartition.Count} messages have timed-out"); foreach (var messageId in headPartition) { var ids = await _unack.Ask <UnAckedChunckedMessageIdSequenceMapCmdResponse>(new UnAckedChunckedMessageIdSequenceMapCmd(UnAckedCommand.Get, new List <IMessageId> { messageId })); foreach (var i in ids.MessageIds) { messagesToRedeliver.Add(i); } messagesToRedeliver.Add(messageId); _unack.Tell(new UnAckedChunckedMessageIdSequenceMapCmd(UnAckedCommand.Remove, new List <IMessageId> { messageId })); _ = MessageIdPartitionMap.TryRemove(messageId, out var _); } headPartition?.Clear(); TimePartitions.Enqueue(headPartition); if (messagesToRedeliver.Count > 0) { _consumer.Tell(new AckTimeoutSend(messagesToRedeliver)); _consumer.Tell(new RedeliverUnacknowledgedMessageIds(messagesToRedeliver)); } } } _timeout = _scheduler.ScheduleTellOnceCancelable(TimeSpan.FromMilliseconds(_ackTimeoutMillis), Self, RunJob.Instance, ActorRefs.NoSender); }