Kafka使用容器方式部署时客户端连接需要注意的事项

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Kafka使用容器方式部署时客户端连接需要注意的事项相关的知识,希望对你有一定的参考价值。

最近在用Docker部署Kafka集群,很多连接需求时需要考虑的,老外的一篇文总结的很到位,但还是有写特别的地方需要注意,以下是原文转载(读懂应该没有问题)。

When a client wants to send or receive a message from Apache Kafka®, there are two types of connection that must succeed:

The initial connection to a broker (the bootstrap). This returns metadata to the client, including a list of all the brokers in the cluster and their connection endpoints.
The client then connects to one (or more) of the brokers returned in the first step as required. If the broker has not been configured correctly, the connections will fail.

What sometimes happens is that people focus on only step 1 above, and get caught out by step 2. The broker details returned in step 1 are defined by the advertised.listeners setting of the broker(s) and must be resolvable and accessible from the client machine.

To read more about the protocol, see the docs, as well as this previous article that I wrote. If the nuts and bolts of the protocol are the last thing you’re interested in and you just want to write applications with Kafka you should check out Confluent Cloud. It’s a fully managed ​​Apache Kafka service in the cloud, with not an advertised.listeners configuration for you to worry about in sight!

Below, I use a client connecting to Kafka in various permutations of deployment topology. It’s written using Python with librdkafka (confluent_kafka), but the principle applies to clients across all languages. You can find the code on GitHub. It’s very simple and just serves to illustrate the connection process. It’s simplified for clarity, at the expense of good coding and functionality

以上是关于Kafka使用容器方式部署时客户端连接需要注意的事项的主要内容,如果未能解决你的问题,请参考以下文章

避免Kafka客户端无法连接Docker上运行的Kafka,又名:Docker如何添加hosts映射

使用C#通过Oracle.DataAccess连接Oracle,部署时需要注意版本问题

带有 Kafka 的 Docker 集群无法与客户端容器建立连接

Kafka集群部署(Docker容器的方式)

Docke容器分离部署LNMP

Sprint 启动 kafka Consumer 无法连接到 kafka 容器