Configure Poller for the specific supplier in Spring Cloud Stream

1.2k views Asked by At

I have an application with multiple suppliers. So, I'm trying to configure fixed-delay for the specific supplier in Spring Cloud Stream. Example:

application.yaml

    spring:
      cloud:
        function:
          definition: produce;produce2 
        stream:
          poller:
            produce: 
              fixedDelay: 10000L
            produce2:
              fixedDelay: 5000L 
          bindings:
            produce-out-0:
              destination: string-output
            produce2-out-0:
              destination: string-output-2

code snippet

    @Configuration
    public class ProducerConfiguration {
    
        private static final Logger LOGGER = LoggerFactory.getLogger(ProducerConfiguration.class);
        
        @Bean
        public Supplier<Object> produce() {
            return () -> {
                LOGGER.info("message");
                return "message";
            };
        }
        
        @Bean
        public Supplier<Object> produce2() {
            return () -> {
                LOGGER.info("message-2");
                return "message-2";
            };
        }
    
    }

But according to spring's documentation https://docs.spring.io/spring-cloud-stream/docs/3.1.2/reference/html/spring-cloud-stream.html#_polling_configuration_properties, It seems to only be able to configure a org.springframework.cloud.stream.config.DefaultPollerProperties bean for whole suppliers in an application. Is this correct?

1

There are 1 answers

2
Oleg Zhurakousky On BEST ANSWER

Indeed this is not supported for functional programming model at the moment as it really violates a concept of microservices for which spring-cloud-stream was designed for, where one of the main principles is you do one thing and do it well without affecting others. And in your case (especially with sources) you have multiple microservices grouped together in a single JVM process, thus one service affecting another.

That said, feel free to raise an issue so we can consider adding this feature