4

I need to set a specific client.id value for Kafka Streams flows with Spring Cloud Stream dynamically.

I know that you can set the value statically as follows:

spring:
  cloud:
    stream:
      kafka:
        streams:
          binder:
            functions:
              kafkaStreamCountWords:
                configuration:
                  client.id: client-id-kafkaStreamCount

But I need to do it dynamically for all streams.

With Spring Cloud Stream Binder Kafka there are customizers for producers and consumers. For example:

  @Bean
  public ConsumerConfigCustomizer consumerConfigCustomizer() {
    return (consumerProperties, bindingName, destination) -> {
      consumerProperties.put(ConsumerConfig.CLIENT_ID_CONFIG, bindingName);
    };
  }

  @Bean
  public ProducerConfigCustomizer producerConfigCustomizer() {
    return (producerProperties, bindingName, destination) -> {
      producerProperties.put(ProducerConfig.CLIENT_ID_CONFIG, bindingName);
    };
  }

But they are not valid for Kafka Stream binder at Function level.

Does anyone know how I can do it for Spring Cloud Stream Kafka Streams?

0 Answers0