.net core 本地:将Kafka与.net core一起使用时主机解析失败
我对使用Kafka是个新手。我有三台使用Kafka的服务器,希望在我的项目中将它们用作消息代理。他们工作得很好,但突然问题开始出现了。 我尝试使用的代码如下:.net core 本地:将Kafka与.net core一起使用时主机解析失败,.net-core,apache-kafka,message-queue,.net Core,Apache Kafka,Message Queue,我对使用Kafka是个新手。我有三台使用Kafka的服务器,希望在我的项目中将它们用作消息代理。他们工作得很好,但突然问题开始出现了。 我尝试使用的代码如下: > using (var adminClient = new AdminClientBuilder(new AdminClientConfig { BootstrapServers = bootStrapServers }).Build()) > { >
> using (var adminClient = new AdminClientBuilder(new AdminClientConfig { BootstrapServers = bootStrapServers }).Build())
> {
> try
> {
> var topicInfo = adminClient.GetMetadata(topicName, TimeSpan.FromSeconds(10));
>
>
> if (topicInfo.Topics.Where(x => x.Error.IsError).Count() == 0)
> await adminClient.DeleteTopicsAsync(new List<string>() { topicName });
>
> await adminClient.CreateTopicsAsync(new TopicSpecification[] {
> new TopicSpecification { Name = topicName, ReplicationFactor = 1, NumPartitions = 1 } });
>
>
> }
> catch (CreateTopicsException e)
> {
> Console.WriteLine($"An error occured creating topic {e.Results[0].Topic}: {e.Results[0].Error.Reason}");
> }
> }
>使用(var adminClient=new AdminClientBuilder(new AdminClientConfig{bootstrapserver=bootstrapserver}).Build())
> {
>试一试
> {
>var topicInfo=adminClient.GetMetadata(topicName,TimeSpan.FromSeconds(10));
>
>
>if(topicInfo.Topics.Where(x=>x.Error.IsError.Count()==0)
>等待adminClient.DeleteTopicsAsync(新列表(){topicName});
>
>等待adminClient.CreateTopicsAsync(新的TopicSpecification[]{
>新的主题规范{Name=topicName,ReplicationFactor=1,NumPartitions=1}});
>
>
> }
>捕获(CreateTopicsException)
> {
>Console.WriteLine($“创建主题{e.Results[0]时出错。主题}:{e.Results[0]。错误。原因}”);
> }
> }
通过执行这一行代码:
var topicInfo=adminClient.GetMetadata(topicName,
时间跨度从秒(10)开始
每个代理的主机名更改为类似于zk-kafka-test245的内容,brokeroriging属性等于-1,运行时错误为
“本地:主机解析失败”引发