Spring Boot @KafkaListener使用SpEL表达式设置属性

sqxo8psd  于 2023-03-08  发布在  Spring
关注(0)|答案(1)|浏览(278)

是否可以使用SpEL将属性列表注入到@KafkaListner注解中?
大概是这样的

@KafkaListener(topics = "topic-name",
            containerFactory = "myContainerFactory",
            groupId = "group-id",
            properties = "#{kafka.consumer.custom.properties}")
    public void onMessage(String msg) {
        log.info(msg);
    }

application.yml

kafka:
  consumer:
    custom:
      properties:
        key.deserializer: org.apache.kafka.common.serialization.IntegerDeserializer
        value.deserializer: org.apache.kafka.common.serialization.StringDeserializer
cx6n0qe3

cx6n0qe31#

请参见https://github.com/spring-projects/spring-kafka/issues/1880#issuecomment-887677779

some:
  prop: |
    max.poll.records: 10
    fetch.min.bytes: 123456
@KafkaListener(id = "kgh1880", topics = "kgh1880",
            properties = "${some.prop}")

相关问题