据我了解,在使用 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)
因此,广告端口的唯一方法是使用侦听器进行设置,这可能很烦人(但作为一种解决方法仍然可行)。