KafkaNet.BrokerRouter.SelectBrokerRouteFromLocalCache C# (CSharp) Method

SelectBrokerRouteFromLocalCache() public method

Select a broker for a given topic using the IPartitionSelector function.
Thrown if the topic metadata does not exist in the cache.
public SelectBrokerRouteFromLocalCache ( string topic, byte key = null ) : KafkaNet.BrokerRoute
topic string The topic to retreive a broker route for.
key byte The key used by the IPartitionSelector to collate to a consistent partition. Null value means key will be ignored in selection process.
return KafkaNet.BrokerRoute
        public BrokerRoute SelectBrokerRouteFromLocalCache(string topic, byte[] key = null)
        {
            //get topic either from cache or server.
            var cachedTopic = GetTopicMetadataFromLocalCache(topic).FirstOrDefault();

            if (cachedTopic == null)
            {
                throw new InvalidTopicNotExistsInCache(String.Format("The Metadata is invalid as it returned no data for the given topic:{0}", topic));
            }

            var partition = _kafkaOptions.PartitionSelector.Select(cachedTopic, key);

            return GetCachedRoute(cachedTopic.Name, partition);
        }

Same methods

BrokerRouter::SelectBrokerRouteFromLocalCache ( string topic, int partitionId ) : KafkaNet.BrokerRoute

Usage Example

        public async Task OffsetCommitShouldStoreAndReturnSuccess()
        {
            const int partitionId = 0;
            using (var router = new BrokerRouter(Options))
            {
                await router.RefreshMissingTopicMetadata(IntegrationConfig.IntegrationTopic);
                var conn = router.SelectBrokerRouteFromLocalCache(IntegrationConfig.IntegrationTopic, partitionId);

                var commit = CreateOffsetCommitRequest(IntegrationConfig.IntegrationConsumer, partitionId, 10);
                var response = conn.Connection.SendAsync(commit).Result.FirstOrDefault();

                Assert.That(response, Is.Not.Null);
                Assert.That(response.Error, Is.EqualTo((int)ErrorResponseCode.NoError));
            }
        }
All Usage Examples Of KafkaNet.BrokerRouter::SelectBrokerRouteFromLocalCache