首页 > 解决方案 > 拦截 Spring Cloud Stream 目标绑定以动态修改生产者属性

问题描述

我试图找到一种方法来拦截 Spring Cloud Stream 3.1.1 目标绑定,以便在我的应用程序中动态修改一些属性。我来到了下面的代码片段,但它似乎只适用于动态绑定,而在我的情况下,通道是专门定义的,并且没有使用动态目标,所以我不确定我在这里缺少什么。

  @Bean
  public NewDestinationBindingCallback<KafkaProducerProperties> bindingConfigurer() {
    return ((channelName, channel, producerProperties, extendedProducerProperties) -> {
      if ("foo".equals(channelName)) {
        producerProperties.setUseNativeEncoding(producerUseNativeEncoding);
        producerProperties.setPartitionCount(producerPartitionCount);
      }
    });
  }

标签: javaspring-kafkaspring-cloud-streamspring-cloud-stream-binder-kafka

解决方案


推荐阅读