apache-kafka - Kafka Schema 注册表 - 在容器中发布动态端口
问题描述
据我了解,在使用 Schema 注册表融合 docker 映像(不是使用 zookeeper 弹性,而是使用 kafka 弹性)时,我们可以使用SCHEMA_REGISTRY_HOST_NAME
env 变量将容器的主机名通告给 Kafka。
如果我尝试使用SCHEMA_REGISTRY_PORT
,我会收到以下错误:
PORT is deprecated. Please use SCHEMA_REGISTRY_LISTENERS instead.
为什么我们不能设置关联的端口?我可以获得这个动态端口(主机动态映射到我的容器的动态端口)但是我应该如何与 Kafka 共享它?
编辑 1:
要添加更多详细信息,以下是模式注册表协调器进行的分配示例:
[2019-10-25 11:55:47,813] INFO Finished rebalance with master election result: Assignment{version=1, error=0, master='sr-1-7a9a403a-63cc-4fed-b548-10ea440863d5', masterIdentity=version=1,host=10.135.124.179,port=29932,scheme=http,masterEligibility=true} (io.confluent.kafka.schemaregistry.masterelector.kafka.KafkaGroupMasterElector)
如您所见,有一个主机名和一个端口(粗体)。主机名来自变量,SCHEMA_REGISTRY_HOST_NAME
但根据代码,端口来自这里:
/**
* A Schema Registry instance's identity is in part the port it listens on. Currently the port can
* either be configured via the deprecated `port` configuration, or via the `listeners`
* configuration.
*
* <p>This method uses `Application.parseListeners()` from `rest-utils` to get a list of
* listeners, and returns the port of the first listener to be used for the instance's identity.
*
* <p></p>In theory, any port from any listener would be sufficient. Choosing the first, instead
* of say the last, is arbitrary.
*/
// TODO: once RestConfig.PORT_CONFIG is deprecated, remove the port parameter.
static SchemeAndPort getSchemeAndPortForIdentity(int port, List<String> configuredListeners,
String requestedScheme)
因此,广告端口的唯一方法是使用侦听器进行设置,这可能很烦人(但作为一种解决方法仍然可行)。
解决方案
listeners
采用 bind-address和 port(s),正如您发现的那样,广告是the port of the first listener to be used for the instance's identity
通过 HTTP 或 HTTPS 侦听 API 请求的侦听器的逗号分隔列表。如果侦听器使用 HTTPS,则还需要设置适当的 SSL 配置参数。
Schema Registry 身份存储在 ZooKeeper 中,由主机名和端口组成。如果配置了多个侦听器,则使用第一个侦听器的端口作为其标识。
类型:列表
默认值:“ http://0.0.0.0:8081 ”
https://docs.confluent.io/current/schema-registry/installation/config.html#listeners
推荐阅读
- javascript - 计时器应该为jquery中forloop中的每个元素开始和结束
- python - 是否有始终以 0.x 开头的浮点数的字符串格式?
- python - 如何在 python 上使用自定义拆分创建新列
- c++ - 以 QMap 作为输入序列的 QtConcurrent map
- r - 为什么filled.contour() 中的轮廓线与contour() 中的轮廓线不完全相同?
- laravel-5 - Laravel 5 Auth::user() 除了 index() 函数和刀片模板外,其他地方都是空的
- ios - 当应用程序到达后台时如何保持计时器计数
- dart - Flutter: Future Builder fetch multiple data
- unity3d - 如何从不同的场景访问对象的组件?
- symfony - 无法使用 symfony ldap 连接到 ldap 服务器