最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

issue with spring.kafka.consumer.ssl.bundle properties not working for SpringBoot Kafka application - Stack Overflow

programmeradmin0浏览0评论

SpringBoot 3 announced the support for SslBundle.

I went to use this code with an app, trying to connect to a SSL kafka.

import java.util.HashMap;
import java.util.Map;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafkamon.config.SslConfigs;
import org.apache.kafkamon.serialization.StringDeserializer;
import org.springframework.boot.autoconfigure.kafka.SslBundleSslEngineFactory;
import org.springframework.boot.ssl.SslBundle;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.annotation.EnableKafka;
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
import org.springframework.kafka.core.ConsumerFactory;
import org.springframework.kafka.core.DefaultKafkaConsumerFactory;

// Annotations
@EnableKafka
@Configuration

// Class
public class KafkaConfig {

    @Bean
    public ConsumerFactory<String, String> consumerFactory(SslBundles sslBundles) {
        Map<String, Object> properties = new HashMap<>();

        // Adding the Configuration
        properties.put(ConsumerConfig.GROUP_ID_CONFIG, "group_id");
        properties.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
        properties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
        properties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "ssl-kafka:9092");

        properties.put("security.protocol", "SSL");

// Not using this anymore in favor of ssl bundle
//        properties.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, "/path/to/keystore.p12");
//        properties.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, "keystorepassword");
//        properties.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, "/path/to/truststore.p12");
//        properties.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, "truststorepassword");

// I am still not sure why this is needed, but it seems to work...
        properties.put(SslConfigs.SSL_ENGINE_FACTORY_CLASS_CONFIG, SslBundleSslEngineFactory.class.getName());
        properties.put(SslBundle.class.getName(), sslBundles.getBundle("mycoolclient"));

        return new DefaultKafkaConsumerFactory<>(properties);
    }
spring.ssl.bundle.pem.mycoolclient.keystore.certificate=/path/to/keystore.cert
spring.ssl.bundle.pem.mycoolclient.keystore.private-key=/path/to/keystore.key
spring.ssl.bundle.pem.mycoolclient.truststore.certificate=/path/to/truststore.cert

And the above seems to work.

I also came across this official document .2.x/reference/html/application-properties.html#application-properties.integration.spring.kafka.consumer.ssl.bundle

And I don't know how to use this property.

I tried with the same ConsumerConfiguration class, but changing the properties to:


#spring.ssl.bundle.pem.mycoolclient.keystore.certificate=/path/to/keystore.cert
#spring.ssl.bundle.pem.mycoolclient.keystore.private-key=/path/to/keystore.key
#spring.ssl.bundle.pem.mycoolclient.truststore.certificate=/path/to/truststore.cert
spring.kafka.consumer.ssl.bundle=whattodohere

And this is not working anymore.

May I ask if anyone has an example of using the spring.kafka.consumer.ssl.bundle property and the correct Configuration class?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论