如何在Spring的yml文件中配置kafka的ssl.enabled.protocols

huangapple go评论71阅读模式
英文:

How to configure kafka for ssl.enabled.protocols in spring yml file

问题

我正在使用springboot + kafka。我在yml文件中进行了所有工厂定义,没有在代码中创建工厂等等,都在yml文件中。

现在我需要确保安全性,但是我找不到如何在application.yml文件中添加 ssl.enabled.protocols 的方法。

我不想创建@Bean定义或@Configuration文件,因为我希望从yml文件中配置所有内容,或者至少只从代码中注入ssl.enabled.protocols

是否有一种方式可以自定义工厂,以便我无需将所有配置定义移至代码中,而只需移动缺失的部分。

英文:

I am using springboot + kafka. I did all the factory definitions in the yml file there is no code creating factories etc, all in yml file.

Now I need to make it secure however I couldn't find how to add ssl.enabled.protocols in the application.yml file.

I don't want to create @Bean definitions or @Configuration files as I want to configure everything from the yml file or at least only somehow inject ssl.enabled.protocols from the code.

Is there a way to customize the factory so that I wouldn't need to move all the configuration definitions into the code but only the missing part.

答案1

得分: 1

您可以使用 spring.kafka.properties[some.property]=foo 来设置任意属性(那些不被 Spring Boot 直接支持的属性)。

> 自动配置支持的属性在附录的“Integration Properties”部分中列出。请注意,大部分这些属性(使用连字符或驼峰命名)直接映射到 Apache Kafka 的属性。有关详细信息,请参阅 Apache Kafka 文档。

> 这些属性中的前几个适用于所有组件(生产者、消费者、管理器和流),但如果您希望使用不同的值,可以在组件级别指定。Apache Kafka 将属性分为高、中、低三个重要性级别。Spring Boot 自动配置支持所有高重要性属性,一些选定的中重要性和低重要性属性,以及没有默认值的任何属性。

> 仅一部分 Kafka 支持的属性可以直接通过 KafkaProperties 类获得。如果您希望配置生产者或消费者的附加属性,而这些属性不受直接支持,请使用以下属性:

spring.kafka.properties[prop.one]=first
spring.kafka.admin.properties[prop.two]=second
spring.kafka.consumer.properties[prop.three]=third
spring.kafka.producer.properties[prop.four]=fourth
spring.kafka.streams.properties[prop.five]=fifth

> 这将设置通用的 prop.one Kafka 属性为 first(适用于生产者、消费者和管理员),将 prop.two 管理属性设置为 second,将 prop.three 消费者属性设置为 third,将 prop.four 生产者属性设置为 fourth,将 prop.five 流属性设置为 fifth。

https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#application-properties.integration.spring.kafka.properties

> 用于配置客户端的生产者和消费者的通用附加属性。

SSL 属性 Spring Boot 直接支持的属性在这里显示:

https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#application-properties.integration.spring.kafka.ssl.key-password

英文:

You can set arbitrary properties (those that are not directly supported by Boot) using spring.kafka.properties[some.property]=foo.

https://docs.spring.io/spring-boot/docs/current/reference/html/messaging.html#messaging.kafka.additional-properties

>The properties supported by auto configuration are shown in the “Integration Properties” section of the Appendix. Note that, for the most part, these properties (hyphenated or camelCase) map directly to the Apache Kafka dotted properties. See the Apache Kafka documentation for details.

>The first few of these properties apply to all components (producers, consumers, admins, and streams) but can be specified at the component level if you wish to use different values. Apache Kafka designates properties with an importance of HIGH, MEDIUM, or LOW. Spring Boot auto-configuration supports all HIGH importance properties, some selected MEDIUM and LOW properties, and any properties that do not have a default value.

>Only a subset of the properties supported by Kafka are available directly through the KafkaProperties class. If you wish to configure the producer or consumer with additional properties that are not directly supported, use the following properties:

spring.kafka.properties[prop.one]=first
spring.kafka.admin.properties[prop.two]=second
spring.kafka.consumer.properties[prop.three]=third
spring.kafka.producer.properties[prop.four]=fourth
spring.kafka.streams.properties[prop.five]=fifth

>This sets the common prop.one Kafka property to first (applies to producers, consumers and admins), the prop.two admin property to second, the prop.three consumer property to third, the prop.four producer property to fourth and the prop.five streams property to fifth.

https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#application-properties.integration.spring.kafka.properties

>Additional properties, common to producers and consumers, used to configure the client.

The SSL properties directly supported by Boot are shown here:

https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#application-properties.integration.spring.kafka.ssl.key-password

huangapple
  • 本文由 发表于 2023年6月22日 14:42:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76529186.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定