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