ASP.Net Core中使用的最多的是Confluent.Kafka这个包,以下用实例展示应用
1.下载Nuget包
首先是下载Confluent.Kafka这个包
2.创建Producer消息生产者
发送者
public class KafkaProducer
{
public static async Task SendAsync(string topic, T value) where T: KafkaMessage
{
var config = new ProducerConfig { BootstrapServers = ConfigEntity.Instance.kafkaMapping.BootstrapServers };//服务器IP
ProducerBuilder producerBuilder = new ProducerBuilder(config);
using (var p = producerBuilder.Build())
{
try
{
var dr = await p.ProduceAsync(topic, new Message { Value = JsonConvert.SerializeObject(value) });
Console.WriteLine($"Delivered '{dr.Value}' to '{dr.TopicPartitionOffset}'");
}
catch (Pro