【问题标题】:Kafka streams attempts to connect to localhost despite StreamsConfig.BOOTSTRAP_SERVERS_CONFIG pointing to a different host尽管 StreamsConfig.BOOTSTRAP_SERVERS_CONFIG 指向不同的主机,但 Kafka 流尝试连接到 localhost
【发布时间】:2021-05-12 01:34:51
【问题描述】:

我有一个如下的 kafka 流配置。我已经在调试器中确认KafkaProperties 确实有一个引导服务器条目,其值为myhost.mydomain.org:9092

当我运行我的应用程序时,我收到警告:

WARN 83530 --- [-StreamThread-1] org.apache.kafka.clients.NetworkClient   : 
[Consumer clientId=...-StreamThread-1-consumer, groupId=mygid] 
Connection to node 1001 (kafka/127.0.0.1:9092) could not be established. Broker may not be available.

我已确认代理已启动并正在运行并接受连接。我不知道它是从哪里获取 localhost 的。

    @Bean("myKSConfig")
    public StreamsBuilderFactoryBean kafkaStreams(KafkaProperties kafkaProperties,
                                     @Value("${spring.application.name}") String appName) {
        var props = new HashMap<String, Object>(kafkaProperties.getProperties());
        props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaProperties.getBootstrapServers());
        props.put(StreamsConfig.APPLICATION_ID_CONFIG, appName);
        props.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
        props.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, JsonSerde.class);
        props.put(StreamsConfig.STATE_DIR_CONFIG, "state_data_dir");
        props.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 10 * 1000);
        props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
        props.put(JsonDeserializer.VALUE_DEFAULT_TYPE, JsonNode.class);
        var config = new KafkaStreamsConfiguration(props);
        return new StreamsBuilderFactoryBean(config);
    }

有了这些属性

...
spring.kafka.bootstrap-servers=myhost.mydomain.org:9092
...

【问题讨论】:

    标签: apache-kafka apache-kafka-streams spring-kafka


    【解决方案1】:

    如果您没有编辑 /etc/hosts 以创建从该地址到 127.0.0.1 的映射,那么引导程序将返回其 advertised.listeners 配置

    检查代理中的配置以验证您的客户端可以连接到广告地址

    【讨论】:

    • 澄清一下;该属性称为引导程序,因为这只是与其中一个代理建立的初始连接;在初始连接之后,集群返回客户端需要连接的实际地址(通过其配置的属性)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-09
    • 1970-01-01
    • 2016-06-30
    • 2020-11-16
    • 2019-08-19
    • 1970-01-01
    相关资源
    最近更新 更多