Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用kafka net在c语言中创建新主题_C#_.net_Apache Kafka - Fatal编程技术网

C# 如何使用kafka net在c语言中创建新主题

C# 如何使用kafka net在c语言中创建新主题,c#,.net,apache-kafka,C#,.net,Apache Kafka,我的家庭控制器如下所示 #region Properties const string topic = "AnotherTestTopic"; const string host = "http://localhost:9092"; #endregion [HttpPost] public ActionResult Save(FormCollection form) { var kafkaOptions = new KafkaOptions(new Uri(host));

我的家庭控制器如下所示

#region Properties

const string topic = "AnotherTestTopic";
const string host = "http://localhost:9092";

#endregion


[HttpPost]
public ActionResult Save(FormCollection form)
{
    var kafkaOptions = new KafkaOptions(new Uri(host));

    var brokerRouter = new BrokerRouter(kafkaOptions);

    var producer = new Producer(brokerRouter);

    producer.SendMessageAsync(topic, new[] { new Message("Test message") }).Wait();

    return RedirectToAction("Index", "Home");
}
我正在使用kafka net dll和SendMessageAsync方法,如下所示

   public async Task<List<ProduceResponse>> SendMessageAsync(string topic, IEnumerable<Message> messages, Int16 acks = 1,
            TimeSpan? timeout = null, MessageCodec codec = MessageCodec.CodecNone)
        {
            if (_stopToken.IsCancellationRequested)
                throw new ObjectDisposedException("Cannot send new documents as producer is disposing.");
            if (timeout == null) timeout = TimeSpan.FromMilliseconds(DefaultAckTimeoutMS);

            var batch = messages.Select(message => new TopicMessage
            {
                Acks = acks,
                Codec = codec,
                Timeout = timeout.Value,
                Topic = topic,
                Message = message
            }).ToList();

            _asyncCollection.AddRange(batch);

            await Task.WhenAll(batch.Select(x => x.Tcs.Task));

            return batch.Select(topicMessage => topicMessage.Tcs.Task.Result)
                                .Distinct()
                                .ToList();
        }
问题:

我刚开始学习卡夫卡。我真的不知道如何从c代码创建主题。如何从c代码添加主题

任何帮助都将不胜感激

谢谢。

您可以在代理配置中设置auto.create.topics.enable=true,以便Kafka在以前未创建主题时为您创建主题


您可能还希望在代理配置中将num.partitions和default.replication.factor设置为适当的值。

配置文件在哪里?在代理的conf目录中;通常称为server.properties