예제 #1
0
        private BrokerRoute TryGetCachedRoute(string topicName, MetadataResponse.Partition partition)
        {
            IConnection conn;

            return(_brokerConnections.TryGetValue(partition.LeaderId, out conn)
                ? new BrokerRoute(topicName, partition.PartitionId, partition.LeaderId, conn)
                : null);
        }
예제 #2
0
        private TopicConnection GetCachedTopicConnection(string topicName, MetadataResponse.Partition partition)
        {
            Endpoint endpoint;
            IImmutableList <IConnection> connections;

            if (_serverEndpoints.TryGetValue(partition.leader, out endpoint) && _connections.TryGetValue(endpoint, out connections))
            {
                var index = _selector.Next(0, connections.Count - 1);
                return(new TopicConnection(topicName, partition.partition_id, partition.leader, connections[index]));
            }

            throw new RoutingException($"Lead server cannot be found for {partition}");
        }
예제 #3
0
        private BrokerRoute GetCachedRoute(string topicName, MetadataResponse.Partition partition)
        {
            var route = TryGetCachedRoute(topicName, partition);

            if (route != null)
            {
                return(route);
            }

            throw new CachedMetadataException($"Lead broker cannot be found for partition/{partition.PartitionId}, leader {partition.LeaderId}")
                  {
                      TopicName = topicName,
                      Partition = partition.PartitionId
                  };
        }