Exemplo n.º 1
0
        public async Task Create(ITopicConfiguration topicConfig)
        {
            if (!_adminClient.TopicExists(topicConfig.Name, out _))
            {
                TopicSpecification topicSpecification = new TopicSpecification
                {
                    Name              = topicConfig.Name,
                    NumPartitions     = topicConfig.Partitions,
                    ReplicationFactor = topicConfig.ReplicationFactor,
                    Configs           = new Dictionary <string, string>
                    {
                        { "retention.ms", topicConfig.RetentionMs.ToString() }
                    }
                };

                try
                {
                    await _adminClient.CreateTopicsAsync(new[] { topicSpecification });
                }
                catch (CreateTopicsException ex)
                {
                    Console.WriteLine(ex);
                }

                _adminClient.EnsureTopicCreation(topicConfig.Name);
            }
        }