Simple Confluent Kafka .net client无法连接到简单构建的AK Kafka broker。

huangapple go评论67阅读模式
英文:

Simple Confluent Kafka .net client fails to connect to simple build of AK Kafka broker

问题

I built Apache Kafka from the 3.4.0 download and followed the quick start successfully (topic created, events produced, events consumed).

Using Confluent.Kafka v2.1.1, I tried to read the topic metadata with:

var adminConfig = new AdminClientConfig();
adminConfig.BootstrapServers = "localhost:9092";
adminConfig.Debug = "all";

using var adminClient = new AdminClientBuilder(adminConfig).Build();
var metadata = adminClient.GetMetadata(TimeSpan.FromSeconds(10));
var topicsMetadata = metadata.Topics;
var topicNames = metadata.Topics.Select(a => a.Topic).ToList();

Console.WriteLine($"Topics: {string.Join(',', topicNames)}");

The var metadata = ... line throws Confluent.Kafka.KafkaException 'Local: Broker transport failure'

The logging in the terminal shows the following which keeps looping:

- xxx: Received CONNECT op
- xxx: Broker changed state INIT -> TRY_CONNECT
- xxx: Broadcasting state change
- xxx: broker in state TRY_CONNECT connecting
- xxx: Broker changed state TRY_CONNECT -> CONNECT
- xxx: Broadcasting state change
- xxx: Connecting to ipv6#[::1]:9092 (plaintext) with socket 1308
- xxx: Connected to ipv6#[::1]:9092
- xxx: localhost:9092/bootstrap: Connected (#12)
- xxx: localhost:9092/bootstrap: Updated enabled protocol features +ApiVersion to ApiVersion
- xxx: Broker changed state CONNECT -> APIVERSION_QUERY
- xxx: Broadcasting state change
- xxx: localhost:9092/bootstrap: Sent ApiVersionRequest (v3, 52 bytes @ 0, CorrId 12)
- xxx: Cluster connection already in progress: no cluster connection
- xxx: Cluster connection already in progress: no cluster connection
- xxx: Cluster connection already in progress: no cluster connection
- xxx: Cluster connection already in progress: no cluster connection
- xxx: Cluster connection already in progress: no cluster connection
- xxx: Cluster connection already in progress: no cluster connection
- xxx: Timed out ApiVersionRequest in flight (after 10115ms, timeout #0)
- xxx: ApiVersionRequest failed: Local: Timed out: probably due to broker version < 0.10 (see api.version.request configuration) (after 10116ms in state APIVERSION_QUERY) (_TRANSPORT): identical to last error: error log suppressed
- xxx: Updated enabled protocol features -ApiVersion to
- xxx: localhost:9092/bootstrap: Broker changed state APIVERSION_QUERY -> DOWN
- xxx: Broadcasting state change
- xxx: Purging bufq with 0 buffers
- xxx: Purging bufq with 0 buffers
- xxx: Updating 0 buffers on connection reset
- xxx: Timed out 1 in-flight, 0 retry-queued, 0 out-queue, 0 partially-sent requests
- xxx: Broker changed state DOWN -> INIT
- xxx: Broadcasting state change
- xxx: Selected for cluster connection: no cluster connection (broker has 11 connection attempt(s))
英文:

Any hints on how to get a simple .Net Kafka client to connect to a broker?

I built Apache Kafka from the 3.4.0 download and followed the quick start successfully (topic created, events produced, events consumed).

Using Confluent.Kafka v2.1.1 I tried to read the topic metadata with:

var adminConfig = new AdminClientConfig();
adminConfig.BootstrapServers = &quot;localhost:9092&quot;;
adminConfig.Debug = &quot;all&quot;;

using var adminClient = new AdminClientBuilder(adminConfig).Build();
var metadata = adminClient.GetMetadata(TimeSpan.FromSeconds(10));
var topicsMetadata = metadata.Topics;
var topicNames = metadata.Topics.Select(a =&gt; a.Topic).ToList();

Console.WriteLine($&quot;Topics: {string.Join(&#39;,&#39;, topicNames)}&quot;);

The var metadata = ... line throws Confluent.Kafka.KafkaException 'Local: Broker transport failure'

The logging in the terminal shows the following which keeps looping:

- xxx: Received CONNECT op
- xxx: Broker changed state INIT -&gt; TRY_CONNECT
- xxx: Broadcasting state change
- xxx: broker in state TRY_CONNECT connecting
- xxx: Broker changed state TRY_CONNECT -&gt; CONNECT
- xxx: Broadcasting state change
- xxx: Connecting to ipv6#[::1]:9092 (plaintext) with socket 1308
- xxx: Connected to ipv6#[::1]:9092
- xxx: localhost:9092/bootstrap: Connected (#12)
- xxx: localhost:9092/bootstrap: Updated enabled protocol features +ApiVersion to ApiVersion
- xxx: Broker changed state CONNECT -&gt; APIVERSION_QUERY
- xxx: Broadcasting state change
- xxx: localhost:9092/bootstrap: Sent ApiVersionRequest (v3, 52 bytes @ 0, CorrId 12)
- xxx: Cluster connection already in progress: no cluster connection
- xxx: Cluster connection already in progress: no cluster connection
- xxx: Cluster connection already in progress: no cluster connection
- xxx: Cluster connection already in progress: no cluster connection
- xxx: Cluster connection already in progress: no cluster connection
- xxx: Cluster connection already in progress: no cluster connection
- xxx: Timed out ApiVersionRequest in flight (after 10115ms, timeout #0)
- xxx: ApiVersionRequest failed: Local: Timed out: probably due to broker version &lt; 0.10 (see api.version.request configuration) (after 10116ms in state APIVERSION_QUERY) (_TRANSPORT): identical to last error: error log suppressed
- xxx: Updated enabled protocol features -ApiVersion to
- xxx: localhost:9092/bootstrap: Broker changed state APIVERSION_QUERY -&gt; DOWN
- xxx: Broadcasting state change
- xxx: Purging bufq with 0 buffers
- xxx: Purging bufq with 0 buffers
- xxx: Updating 0 buffers on connection reset
- xxx: Timed out 1 in-flight, 0 retry-queued, 0 out-queue, 0 partially-sent requests
- xxx: Broker changed state DOWN -&gt; INIT
- xxx: Broadcasting state change
- xxx: Selected for cluster connection: no cluster connection (broker has 11 connection attempt(s))

答案1

得分: 1

错误消息原来是误导性的,未成功连接到代理。从这篇文章中,我发现本地主机地址在WSL和Windows系统之间并不总是正确映射。

我成功在WSL中使用akhq,在Windows上将其视为本地主机(http://localhost:8080/ui/local/topic) - 尽管kafka代理作为本地主机不起作用(BootstrapServers = "localhost:9092"生成错误,但BootstrapServers = "172.18.212.44:9092"成功)。

如果Kafka社区的任何人看到这个 - 也许可以改进日志记录以帮助识别问题。具体来说,日志行"- xxx: 代理更改状态 CONNECT -> APIVERSION_QUERY"似乎表明连接成功,而API版本查询是失败的 - 这并不是事实。

英文:

The error message turned out to be misleading, a connection was NOT successfully made to the broker.

From this article, I discovered that the localhost address does not always correctly map between the WSL and Windows system.

I used akhq successfully running within WSL, from Windows as localhost (http://localhost:8080/ui/local/topic) - though the kafka broker did not work as localhost (BootstrapServers = "localhost:9092" generates the error, though BootstrapServers = "172.18.212.44:9092" succeeds).

If anyone in the Kafka community sees this - perhaps the logging could be improved to help identify the issue. Specifically, the log line "- xxx: Broker changed state CONNECT -> APIVERSION_QUERY" seems to indicate the connection was successful, and the query for api version is what was failing - which is not the case.

huangapple
  • 本文由 发表于 2023年5月14日 23:19:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76248233.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定