spring-cloud-stream-binder-kafka使用密碼連接與SSL配置

在使用spring-cloud-stream-binder-kafka時,在kafka服務開啓登錄認證之後需要客戶端提供用戶名密碼纔可以鏈接,需要在配置文件中做如下配置:

pom文件:

<dependency>
     <groupId>org.springframework.cloud</groupId>
     <artifactId>spring-cloud-stream-binder-kafka</artifactId>
     <version>XX</version>
</dependency>

配置文件:

spring:
  cloud:
    stream:
      default-binder: kafka
      kafka:
        binder:
          brokers: ip:port,ip:port,...
          configuration:
            security:
              protocol: SASL_SSL
            sasl:
              mechanism: PLAIN
            ssl:
              truststore:
                location: XX/XX/truststore.jks
                password: 證書密碼
              cipher:
                suites: 加密套件1,加密套件2,...
              endpoint:
              	identification:
              		algorithm:''

配置文件中ssl開始的配置爲kafka的SSL鏈接配置,如kakfa服務沒有開啓SSL請勿配置!!!
如想了解更多關於SSL配置項,請參考kafka-client.jar中的SslConfig類

通過用戶名密碼連接配置:

1. springboot可以在啓動啓動類設置JVM參數:
System.setProperty("java.security.auth.login.config","classpath:kafka_auth.conf");
  1. 創建一個名爲KafkaLoginModule.java類,實現javax.security.auth.spi.LoginModule接口並實現裏面的方法, 方法具體實現方式可參考kafka-client.jar中的PlainLoginModule類

kafka_auth.conf配置文件:

KafkaClient {
    com.XXX.XXX.KafkaLoginModule required
	username="XXX"  #kafka用戶名
	password="XXX"; #kafka密碼
};
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章