Spring Kafka 消费者无法连接到代理

时间:2021-06-03 17:01:41

标签: java spring spring-boot apache-kafka spring-kafka

我正在尝试使用 ssl enable 进行 Kafka 消费者配置,但无法连接。 我使用了 Spring boot 2.3.3.RELEASE 并且各自的 Kafka-client & Spring Kafka 是由父依赖拉的。 这是一些代码片段-

    Map<String, Object> config = new HashMap<String, Object>();
    config.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaBootStrapServers);
    config.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
    config.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
    config.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "true");
    
    if (sslEnabled) {
        config.put(SslConfigs.SSL_PROTOCOL_CONFIG, "SSL");
        config.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, trustStoreLocation);
        config.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, trustStorePassword);
        config.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG, keyStorePassword);
        config.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, keyStorePassword);
        config.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, keyStoreLocation);
    }

我在上面的配置中收到低于警告,它每秒钟都在写日志。

groupId=dp-cds-consumer-group] Bootstrap broker sd-5ea4-f0b6.apac.nsroot.net:9093 (id: -2 rack: null) disconnected
2021-06-02 16:30:09.791  WARN 447 --- [Container-0-C-1] o.a.k.c.NetworkClient                    : [Consumer clientId=consumer-dp-cos-consumer-group-2, groupId=dp-cos-consumer-group] Bootstrap broker sd-1c3f-5bcc.apac.nsroot.net:9093 (id: -1 rack: null) disconnected
2021-06-02 16:30:10.005  WARN 447 --- [Container-0-C-1] o.a.k.c.NetworkClient                    : [Consumer clientId=consumer-dp-etrs-consumer-group-3, groupId=dp-etrs-consumer-group] Bootstrap broker sd-5ea4-f0b6.apac.nsroot.net:9093 (id: -2 rack: null) disconnected
2021-06-02 16:30:10.283  WARN 447 --- [Container-0-C-1] o.a.k.c.NetworkClient 

如果我使用 config.put(SslConfigs.SSL_PROTOCOL_CONFIG, "SSL"); 而不是 config.put("security.protocol", securityProtocol); 那么我会遇到以下异常:-

java.lang.IllegalArgumentException: No enum constant org.apache.kafka.common.security.auth.SecurityProtocol.SSL.SECURITY.PROTOCOL

如果此处缺少更多配置,请建议添加以解决问题。

0 个答案:

没有答案