Ich habe Homecontroller wie unten,Wie mithilfe von kafka-net
#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");
}
I kafka-net dll und meine SendMessageAsync Methode wie unten
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();
}
bin mit neuem Thema in C# erstellen
Frage:
ich lea gerade erst begonnen rning kafka.Ich weiß wirklich nicht, wie ich Thema von C# code erstellen kann. Wie kann ich Thema von C# hinzufügen?
Jede Hilfe wird geschätzt.
Danke.
wo sind die Konfigurationsdateien? –
es ist in Ihrem Broker conf-Verzeichnis; normalerweise 'server.properties' genannt – alirabiee