首页 > 解决方案 > Kafka Schema 注册表 - 在容器中发布动态端口

问题描述

据我了解,在使用 Schema 注册表融合 docker 映像(不是使用 zookeeper 弹性,而是使用 kafka 弹性)时,我们可以使用SCHEMA_REGISTRY_HOST_NAMEenv 变量将容器的主机名通告给 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)

https://github.com/confluentinc/schema-registry/blob/5af0ca3be1138fe483d0f90f4ccfd4f02f158334/core/src/main/java/io/confluent/kafka/schemaregistry/storage/KafkaSchemaRegistry.java#L211-L223

因此,广告端口的唯一方法是使用侦听器进行设置,这可能很烦人(但作为一种解决方法仍然可行)。

标签: apache-kafkaconfluent-schema-registrynomad

解决方案


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


推荐阅读