Example #1
0
        /// <summary>
        /// Adds committable offset to existing ones
        /// </summary>
        private ICommittableOffsetBatch UpdateWithOffset(ICommittableOffset committableOffset)
        {
            var partitionOffset = committableOffset.Offset;
            var metadata        = (committableOffset is ICommittableOffsetMetadata withMetadata) ? withMetadata.Metadata : string.Empty;

            var newOffsets = OffsetsAndMetadata.SetItem(partitionOffset.GroupTopicPartition, new OffsetAndMetadata(partitionOffset.Offset, metadata));
            var committer  = committableOffset is CommittableOffset c
                ? c.Committer
                : throw new ArgumentException($"Unknown committable offset, got {committableOffset.GetType().Name}, expected {nameof(committableOffset)}");


            IImmutableDictionary <string, IInternalCommitter> newCommitters = ImmutableDictionary <string, IInternalCommitter> .Empty;

            if (Committers.TryGetValue(partitionOffset.GroupId, out var groupCommitter))
            {
                if (!groupCommitter.Equals(committer))
                {
                    throw new ArgumentException($"CommittableOffset {committableOffset} committer for groupId {partitionOffset.GroupId} " +
                                                $"must be same as the other with this groupId.");
                }

                newCommitters = Committers;
            }
            else
            {
                newCommitters = Committers.SetItem(partitionOffset.GroupId, committer);
            }

            return(new CommittableOffsetBatch(newOffsets, newCommitters, BatchSize + 1));
        }
        public ICommittableOffsetBatch Updated(ICommittableOffset offset)
        {
            var partitionOffset = offset.PartitionOffset;
            var key             = partitionOffset.Key;

            var newOffsets = Offsets.SetItem(key, offset.PartitionOffset.Offset);
            var stage      = ((CommittableOffset)offset).Committer;

            ICommitter s;
            IImmutableDictionary <string, ICommitter> newStages;

            if (stages.TryGetValue(key.GroupId, out s))
            {
                if (s != stage)
                {
                    throw new ArgumentException();
                }
                newStages = stages;
            }
            else
            {
                newStages = stages.SetItem(key.GroupId, stage);
            }

            return(new CommittableOffsetBatch(newOffsets, newStages));
        }
Example #3
0
 /// <summary>
 /// Create an offset batch out of a first offsets.
 /// </summary>
 public static ICommittableOffsetBatch Create(ICommittableOffset offset) => Empty.Updated(offset);
 public CommittableMessage(T record, ICommittableOffset offset)
 {
     Record = record;
     Offset = offset;
 }
Example #5
0
 public CommittableMessage(ConsumeResult <K, V> record, ICommittableOffset commitableOffset)
 {
     Record           = record;
     CommitableOffset = commitableOffset;
 }
Example #6
0
 public CommittableMessage(ICommittableOffset offset, RdKafka.Message record)
 {
     Offset = offset;
     Record = record;
 }