0

I'm struggling to find in google/spring docs any way to make the Spring Container properties set in the yml file instead of programatically.

I want to set the property "idleBetweenPolls" for one specific topic + consumer.

I've achieved it programatically (it is currently applying to all topics/consumers, I'd need to add some conditions there).

@Bean
public ListenerContainerCustomizer<AbstractMessageListenerContainer<?, ?>> customizer() {
    return (container, dest, group) -> {
        log.info("Container : {}, dest: {}, group: {}", container, dest, group);
        container.getContainerProperties().setIdleBetweenPolls(15000);
    };

}

How can I set that at yml level? I tried the config below with no success:

spring.cloud.stream:
  kafka:
    binder:
      autoCreateTopics: true
      autoAddPartitions: true
      healthTimeout: 10
      requiredAcks: 1
      minPartitionCount: 1
      replicationFactor: 1
      headerMapperBeanName: customHeaderMapper
    bindings:
      command-my-setup-input-channel:
        consumer:
          autoCommitOffset: false
          batch-mode: true
          startOffset: earliest
          resetOffsets: true
          converter-bean-name: batchConverter
          ackMode: manual
          idleBetweenPolls: 90000 # not working
          configuration:
            heartbeat.interval.ms: 1000
            max.poll.records: 2
            max.poll.interval.ms: 890000
            value.deserializer: com.xpto.MySetupDTODeserializer
  bindings:
    command-my-setup-input-channel:
      destination: command.my.setup
      content-type: application/json
      binder: kafka
      configuration:
        value:
          deserializer: com.xpto.MySetupDTODeserializer
      consumer:
        batch-mode: true
        startOffset: earliest
        resetOffsets: true

Version: spring-cloud-stream 3.0.12.RELEASE

Lucas
  • 129
  • 9
  • You could try using a place holder eg : @Value("${idleBetweenPolls}") int idleBetweenPolls – Dev-vruper Dec 29 '22 at 10:48
  • Hi @Dev-vruper, that's correct. But what I'm trying to achieve is moving the bean to the YML file directly, not needing any code. – Lucas Dec 29 '22 at 11:28
  • Boot does not support all container properties in yml, just some of the common ones; your current solution is correct. – Gary Russell Jan 03 '23 at 15:59

1 Answers1

1

Boot does not support all container properties in yml, just some of the common ones; your current solution is correct.

You could open a new feature suggestion against Boot.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179