我正在尝试创建一个Kafka制作人和消费者,但我的项目是在dotnet Core 2.0中,它似乎与kafka不兼容。这是我尝试过的概念验证。我正在使用Visual Studio 2017和kafka-net nuget包:
使用
using KafkaNet;
using KafkaNet.Model;
using KafkaNet.Protocol;
生产者
static void Main(string[] args)
{
string payload = "Welcome to Kafka!";
string topic = "IDGTestTopic";
Message msg = new Message(payload);
Uri uri = new Uri("localhost:9092");
var options = new KafkaOptions(uri);
var router = new BrokerRouter(options);
var client = new Producer(router);
client.SendMessageAsync(topic, new List<Message> { msg }).Wait();
Console.ReadLine();
}
消费者
static void Main(string[] args)
{
string topic = "IDGTestTopic";
Uri uri = new Uri("http://localhost:9092");
var options = new KafkaOptions(uri);
var router = new BrokerRouter(options);
var consumer = new Consumer(new ConsumerOptions(topic, router));
foreach (var message in consumer.Consume())
{
Console.WriteLine(Encoding.UTF8.GetString(message.Value));
}
Console.ReadLine();
}
当我尝试首先运行生产者时,我在BrokerRouter上收到一条错误消息:
$exception {System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: port
at System.Net.IPEndPoint..ctor(IPAddress address, Int32 port)
at KafkaNet.DefaultKafkaConnectionFactory.Resolve(Uri kafkaAddress, IKafkaLog log)
at KafkaNet.Model.KafkaOptions.<get_KafkaServerEndpoints>d__0.MoveNext()
at KafkaNet.BrokerRouter..ctor(KafkaOptions kafkaOptions)
at SampleKafkaProducer.Program.Main(String[] args) in C:\v4target\SampleKafka\SampleKafkaProducer\SampleKafkaProducer\Program.cs:line 18} System.ArgumentOutOfRangeException
9092的端口如何超出范围?我的Visual Studio项目正在55000的端口上运行。我研究过的多个来源使用9092作为kafka端口。
有没有人理解错误信息?是主要问题的一部分因为我使用的是与dotnet核心不兼容的Kafka版本吗?