Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-8482

Camel requires restart of Spring applicationcontext to fetch new values for properties managed by Spring Cloud

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Cannot Reproduce
    • 2.15.0
    • None
    • camel-spring-boot
    • None
    • Unknown

    Description

      When having a camel route builder making use of a property managed by spring cloud config server, the beans in the application managed by Spring get the property values refreshed when invoking the Spring cloud config RefreshEndpoint but the camel routebuilders does not pick up the new values. Restarting the camel context does not help either. Restart of Spring application context is required.

      Example that works for Spring managed beans:

      package se.comhem.service;

      import org.springframework.beans.factory.annotation.Value;
      import org.springframework.cloud.context.config.annotation.RefreshScope;
      import org.springframework.stereotype.Component;

      @Component
      @RefreshScope()
      public class CosmosProperties {

      @Value("${cosmos.someappconf}")
      private String someAppConf;

      public String getSomeAppConf()

      { return someAppConf; }

      }

      When using this bean together with a camel routebuilder it does not work until Spring Application context is restarted:

      package se.comhem.service;

      import org.apache.camel.model.language.SimpleExpression;
      import org.apache.camel.spring.SpringRouteBuilder;
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.stereotype.Component;

      @Component
      public class ConfigClientRouteBuilder extends SpringRouteBuilder {
      pansowa
      private final static String URI = "servlet:///testCamel";

      @Autowired
      private CosmosProperties cosmosProperties;

      @Override
      public void configure() throws Exception

      { from(URI) .setBody(new SimpleExpression(cosmosProperties.getSomeAppConf())) .to("log:se.comhem?level=INFO&showBody=true&multiline=true") .end(); }

      }

      Main application class:

      package se.comhem.service;

      import org.apache.camel.component.servlet.CamelHttpTransportServlet;
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.boot.SpringApplication;
      import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
      import org.springframework.boot.context.embedded.ServletRegistrationBean;
      import org.springframework.context.annotation.Bean;
      import org.springframework.context.annotation.ComponentScan;
      import org.springframework.context.annotation.Configuration;
      import org.springframework.web.bind.annotation.RequestMapping;
      import org.springframework.web.bind.annotation.RestController;

      @Configuration
      @EnableAutoConfiguration
      @RestController
      @ComponentScan
      public class Application {

      private static final String CAMEL_URL_MAPPING = "/camel/*";
      private static final String CAMEL_SERVLET_NAME = "CamelServlet";

      @Autowired
      private CosmosProperties cosmosProperties;

      @RequestMapping("/")
      public String home()

      { return "Config client running correctly"; }

      public static void main( String[] args )

      { SpringApplication.run(Application.class, args); }

      @RequestMapping("/some-app-conf")
      public String someAppConf()

      { return "Some app conf " + this.cosmosProperties.getSomeAppConf(); }

      @Bean
      public ServletRegistrationBean servletRegistrationBean()

      { ServletRegistrationBean registration = new ServletRegistrationBean(new CamelHttpTransportServlet(), CAMEL_URL_MAPPING); registration.setName(CAMEL_SERVLET_NAME); return registration; }

      }

      Bootstrap configuration

      spring:
      boot:
      admin:
      url: http://localhost:8880
      application:
      name: config-client
      config:
      name: config-client
      profiles:
      active: ${environment}
      cloud:
      config:
      uri: http://localhost:8110
      enabled: true
      failFast: true

      pom:

      <?xml version="1.0" encoding="UTF-8"?>
      <project xmlns="http://maven.apache.org/POM/4.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>

      <groupId>se.comhem.service</groupId>
      <artifactId>config-client</artifactId>
      <version>1.0-SNAPSHOT</version>

      <properties>
      <org.springframework.version>4.1.5.RELEASE</org.springframework.version>
      <camel.version>2.15.0</camel.version>
      <java.version>1.8</java.version>
      </properties>

      <dependencyManagement>
      <dependencies>
      <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-parent</artifactId>
      <version>1.0.0.RELEASE</version>
      <type>pom</type>
      <scope>import</scope>
      </dependency>
      </dependencies>
      </dependencyManagement>

      <dependencies>

      <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      <exclusions>
      <exclusion>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
      </exclusion>
      <exclusion>
      <groupId>org.slf4j</groupId>
      <artifactId>log4j-over-slf4j</artifactId>
      </exclusion>
      </exclusions>
      </dependency>

      <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-jetty</artifactId>
      </dependency>

      <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
      </dependency>

      <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter</artifactId>
      </dependency>

      <dependency>
      <groupId>de.codecentric</groupId>
      <artifactId>spring-boot-starter-admin-client</artifactId>
      <version>1.1.2</version>
      </dependency>

      <dependency>
      <groupId>se.comhem.common</groupId>
      <artifactId>decrypt</artifactId>
      <version>1.0.0</version>
      </dependency>

      <!-- Camel -->
      <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-core</artifactId>
      <version>${camel.version}</version>
      <exclusions>
      <exclusion>
      <artifactId>slf4j-api</artifactId>
      <groupId>org.slf4j</groupId>
      </exclusion>
      </exclusions>
      </dependency>
      <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-spring-boot</artifactId>
      <version>${camel.version}</version>
      </dependency>
      <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-servlet</artifactId>
      <version>${camel.version}</version>
      </dependency>

      </dependencies>

      <build>
      <resources>
      <resource>
      <directory>src/main/resources</directory>
      <filtering>true</filtering>
      </resource>
      </resources>

      <plugins>
      <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
      <executions>
      <execution>
      <goals>
      <goal>repackage</goal>
      </goals>
      </execution>
      </executions>
      </plugin>
      <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.2</version><!-$NO-MVN-MAN-VER$->
      <configuration>
      <source>${java.version}</source>
      <target>${java.version}</target>
      </configuration>
      </plugin>
      <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-source-plugin</artifactId>
      <executions>
      <execution>
      <id>attach-sources</id>
      <phase>verify</phase>
      <goals>
      <goal>jar-no-fork</goal>
      </goals>
      </execution>
      </executions>
      </plugin>
      </plugins>
      </build>

      </project>

      Attachments

        1. config-client.zip
          114 kB
          Manuel Rivas

        Issue Links

          Activity

            People

              hekonsek Henryk Konsek
              manolitorivas Manuel Rivas
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: