3

I have a Camel Spring Boot application where I am printing the value of a property which is set using Spring Cloud Config Server (via Git commit id plugin). The issue is that the value of the property in Camel application is not updated once the value is committed to Git. I have to restart the Camel application which fails the purpose of Spring Cloud Config server. Please note that we are using Git file system in our local machine.

The name of the properties file is CamelSpringBootSample-dev.properties.

As soon as I commit, the config server publishes the updated value at the endpoint on refresh: http://localhost:8888/CamelSpringBootSample/dev

I have also made the Camel application end point available at: http://localhost:8181/actuator/env

Here the value of the property is not updated on refresh. However, if I restart the Camel application, the value is reflecting.

The source code for all the three projects are uploaded in github.com.

  1. The config server: https://github.com/sreejeshraj/config-server

  2. The Camel client project (which uses the config server to configure itself): https://github.com/sreejeshraj/camel-config-server Please do not get misled by the repository name camel-config-server. This is the client of config server, but I accidentally named it incorrectly, apologies.

  3. The local git repository where the configuration properties are stored: https://github.com/sreejeshraj/Git-Config

Please note that I have used the annotation @RefreshScope in my Spring bean component class.

Can you please help me with this? Thanks in advance.

SRaj
  • 1,168
  • 1
  • 14
  • 36
  • Can you edit your question and the code of the bean annotated with `@RefreshScope`? – Ortomala Lokni Aug 20 '19 at 18:41
  • The bean annotated with @RefreshScope is available at https://github.com/sreejeshraj/camel-config-server/blob/master/src/main/java/com/ustglobal/demo/route/CamelDemoRoute.java – SRaj Aug 20 '19 at 18:55

3 Answers3

3

You have to set:

management.endpoints.web.exposure.include=refresh

in bootstrap.properties or bootstrap.yml.

and trigger the /actuator/refresh endpoint.

See @RefreshScope and /refresh not working

Note that as said in the comments, Camel does not update its values when a Spring beans is refreshed and there is no plan to implement this feature. (https://issues.apache.org/jira/browse/CAMEL-13892). You probably could find a solution through Spring Cloud Bus.

Ortomala Lokni
  • 56,620
  • 24
  • 188
  • 240
  • Thanks Ortomala Lokni for pointing that out. I have POSTed the /actuator/refresh endpoint. What happened was a bit strange: 1. When I invoked http://localhost:8181/actuator/env endpoint (which belongs to Camel application), the updated value of the property is reflected as expected. 2. But Camel still was using the old value while it was printing. Basically, the application did not use the updated value. Can you please help? – SRaj Aug 21 '19 at 05:56
  • On restarting the Camel application, it reflects the updated value. However, that fails the purpose of Spring Cloud config. – SRaj Aug 21 '19 at 06:04
  • Try to print out the refreshed value directly from the bean with the `@RefreshScope` annotation. The problem is probably that Camel doesn't re-read the value. – Ortomala Lokni Aug 21 '19 at 07:06
  • 1
    Yeah, the refresh is a Spring Actuator feature, it just refreshes annotated Spring Beans and does not know about Camel. Therefore it depends how you use the updated property in Camel. It must be reevaluated on message processing, otherwise, it cannot use the updated value. – burki Aug 21 '19 at 07:40
  • Thanks Ortomala and Burki. It seems that is the case. Camel is not using the updated property. I tested using Camel, even tried to print the property in the Camel route (also tried to print the value from an Autowired bean as well). In both cases, Camel did not update the property after calling refresh. I will write a REST service with the same setup and update the results later. So I probably have to report this to Camel team in their JIRA system. – SRaj Aug 21 '19 at 13:09
  • I just tested it. You guys are right. The REST service is working as expected - it updates the property value after we call refresh endpoint (POST). This is probably a Camel thing then.. – SRaj Aug 21 '19 at 13:36
  • 1
    Camel does not support the Spring Cloud configuration feature - got it officially confirmed. Please see https://issues.apache.org/jira/browse/CAMEL-13892 – SRaj Aug 22 '19 at 06:28
1

As @ortomala-lokni already pointed out, you need to refresh your configuration consumers after an update happened.

If you want a centralized solution for this task (for refreshing many components automatically), take a look at Spring Cloud Bus.

This page gives a quite good overview about the subject.

burki
  • 6,741
  • 1
  • 15
  • 31
  • Thanks Burki, I was about to try Spring Cloud Bus later. Regarding the refresh endpoint, please see my comments below Ortomala's reply. – SRaj Aug 21 '19 at 06:00
0

I had a situation where I had both application.properties and bootstrap.properties file in my client. I that case you should specify spring.application.name and spring.cloud.config.server.git.uri inside bootstrap.yml. I didn't refresh properties having spring.application.name inside applicaiton.properties.

chAmi
  • 1,774
  • 3
  • 20
  • 27