spring-cloud / spring-cloud-consul

Spring Cloud Consul
http://cloud.spring.io/spring-cloud-consul/
Apache License 2.0
813 stars 541 forks source link

Consul Config - change affected bean not recreated #472

Closed zoltan-toth-mw closed 5 years ago

zoltan-toth-mw commented 5 years ago

Hi There,

Whenever I change kafka.producer.topic in my consul config the following bean is not recreated with the new kafka.producer.topic value. Though according to the logs, the app noticed the change:

Refresh keys changed: [kafka.producer.topic]

    @Service
    public class RabbitToKafkaShovel {

      private static final Logger LOG = LoggerFactory.getLogger(RabbitToKafkaShovel.class);

      private final KafkaProducer<Long, byte[]> kafka;
      private final String producerTopic;

      @Autowired
      public RabbitToKafkaShovel(KafkaProducer<Long, byte[]> kafka, @Value("${kafka.producer.topic}") String producerTopic) {
          this.kafka = kafka;
          this.producerTopic = producerTopic;
      }

      // other methods
    }

I tried with spring-boot 1.5.15.RELEASE and spring-cloud-starter-consul-config 1.3.4.RELEASE and spring-boot 2.1.0.RELEASE and spring-cloud-starter-consul-config 2.1.0.M2

spencergibb commented 5 years ago

@Value doesn't automatically get rebound like @ConfigurationProperties. In this case, RabbitToKafkaShovel will need to be annotated with @RefreshScope.

zoltan-toth-mw commented 5 years ago

@spencergibb

@RefreshScope didn't work.

spencergibb commented 5 years ago

If you can you provide a complete, minimal, verifiable sample that reproduces the problem, I'll reopen the issue. It should be available as a GitHub (or similar) project or attached to this issue as a zip file.

zoltan-toth-mw commented 5 years ago

@spencergibb here you are: https://github.com/zoltan-toth-mw/consul-test

The issue is related to @RabbitListener as if I create the SimpleMessageListenerContaier and add the RabbitListenerService as a channel aware message listener to it instead of using @RabbitListener than the change is picked up.