Exemplo n.º 1
0
        private static bool TopicExists(string topicName)
        {
            var config = new AdminClientConfig()
            {
                BootstrapServers = _server
            };

            using (var client = new AdminClient(config))
            {
                // Which call auto-creates the topic?
                var metaBroker = client.GetMetadata(TimeSpan.FromSeconds(3));
                var metaTopic  = client.GetMetadata(_topicName, TimeSpan.FromSeconds(3));   // Auto-creates topic. Broker setting?

                var resources = new List <ConfigResource>()
                {
                    new ConfigResource()
                    {
                        Name = _topicName, Type = ResourceType.Topic
                    }
                };
                var options = new DescribeConfigsOptions()
                {
                    RequestTimeout = TimeSpan.FromSeconds(3)
                };

                var configTask    = client.DescribeConfigsAsync(resources, options);
                var configResults = configTask.Result;
            }

            return(false);
        }
    public async Task <ResourceConfig> GetBrokerConfigAsync(int brokerId, TimeSpan timeout)
    {
        var resource = new ConfigResource
        {
            Name = brokerId.ToString(),
            Type = ResourceType.Broker
        };

        var options = new DescribeConfigsOptions
        {
            RequestTimeout = timeout
        };

        ICollection <DescribeConfigsResult> results;

        try
        {
            results = await _adminClient.DescribeConfigsAsync(new[] { resource }, options);
        }
        catch (KafkaException e)
        {
            throw new AdminClientException("Unable to get broker config.", e);
        }

        return(Map(results.First()));
    }
 public Task <List <DescribeConfigsResult> > DescribeConfigsAsync(IEnumerable <ConfigResource> resources, DescribeConfigsOptions options = null)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 4
0
 public Task <List <DescribeConfigsResult> > DescribeConfigsAsync(IEnumerable <ConfigResource> resources, DescribeConfigsOptions options = null)
 {
     return(Task.FromResult(new List <DescribeConfigsResult>
     {
         new DescribeConfigsResult
         {
             Entries = new Dictionary <string, ConfigEntryResult>
             {
                 { "num.partitions", new ConfigEntryResult {
                       IsDefault = true,
                       IsReadOnly = true,
                       IsSensitive = false,
                       Name = "num.partitions",
                       Value = "1",
                       Source = ConfigSource.DefaultConfig
                   } }
             }
         }
     }));
 }
 public Task <List <DescribeConfigsResult> > DescribeConfigsAsync(IEnumerable <ConfigResource> resources, DescribeConfigsOptions options = null)
 {
     return(Task.FromResult(new List <DescribeConfigsResult>
     {
         new DescribeConfigsResult
         {
             Entries = new Dictionary <string, ConfigEntryResult>
             {
                 { "num.partitions", new ConfigEntryResult {
                       IsDefault = true,
                       IsReadOnly = true,
                       IsSensitive = false,
                       Name = "num.partitions",
                       Value = cluster.DEFAULT_NUMBER_PARTITIONS.ToString(),
                       Source = ConfigSource.DefaultConfig
                   } },
                 { "replication.factor", new ConfigEntryResult {
                       IsDefault = true,
                       IsReadOnly = true,
                       IsSensitive = false,
                       Name = "replication.factor",
                       Value = "1",
                       Source = ConfigSource.DefaultConfig
                   } },
             }
         }
     }));
 }