コード例 #1
0
        /// <summary>
        /// Get offsets for a single partitions of a given topic.
        /// </summary>
        /// <param name="router">The router which provides the route and metadata.</param>
        /// <param name="topicName">Name of the topic to get offset information from.</param>
        /// <param name="partitionId">The partition to get offsets for.</param>
        /// <param name="maxOffsets">How many to get, at most.</param>
        /// <param name="offsetTime">These are best described by <see cref="OffsetsRequest.Topic.timestamp"/></param>
        /// <param name="cancellationToken"></param>
        public static async Task <OffsetsResponse.Topic> GetOffsetsAsync(this IRouter router, string topicName, int partitionId, int maxOffsets, long offsetTime, CancellationToken cancellationToken)
        {
            var request  = new OffsetsRequest(new OffsetsRequest.Topic(topicName, partitionId, offsetTime, maxOffsets));
            var response = await router.SendAsync(request, topicName, partitionId, cancellationToken).ConfigureAwait(false);

            return(response.responses.SingleOrDefault(t => t.topic == topicName && t.partition_id == partitionId));
        }
コード例 #2
0
        public void OffsetsRequest(
            [Values(0, 1)] short version,
            [Values("testTopic")] string topic,
            [Values(1, 10)] int topicsPerRequest,
            [Values(1, 5)] int totalPartitions,
            [Values(-2, -1, 123456, 10000000)] long time,
            [Values(1, 10)] int maxOffsets)
        {
            var topics = new List <OffsetsRequest.Topic>();

            for (var t = 0; t < topicsPerRequest; t++)
            {
                var offset = new OffsetsRequest.Topic(topic + t, t % totalPartitions, time, version == 0 ? maxOffsets : 1);
                topics.Add(offset);
            }
            var request = new OffsetsRequest(topics);

            request.AssertCanEncodeDecodeRequest(version);
        }