DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Auto Logging in Class and Method Level Using Custom Annotations in Spring Boot App
  • Spring Boot Pet Clinic App: A Performance Study
  • Aggregating REST APIs Calls Using Apache Camel
  • Improving Backend Performance Part 1/3: Lazy Loading in Vaadin Apps

Trending

  • The "Just Read the Code" Myth Is Killing Your AI Workflow
  • Using the Anthropic Evaluation Tool to Check the Claude Code Plugin Efficiency
  • Managing Technical Debt in AI-Generated Code
  • Kafka vs Flink vs Spark: Do You Really Need Real-Time?

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Frameworks
  4. Externalize Apache Camel Route Configurations for Spring Boot Apps

Externalize Apache Camel Route Configurations for Spring Boot Apps

Time to get your Camel where it needs to go.

By 
Vignesh Prabhu
·
Jan. 31, 21 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
7.2K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

In this article, we will discuss how we can externalize Apache Camel route configurations in a Spring Boot application using Spring profiles.

Below is a sample code of a Camel Route, which we will externalize.

Java
 




x
16


 
1
package com.demo.camelspringboot.route;
2

          
3
import org.apache.camel.builder.RouteBuilder;
4
import org.springframework.stereotype.Component;
5

          
6
@Component
7
public class CamelRoute extends RouteBuilder {
8
    @Override
9
    public void configure() throws Exception {
10
        from("timer:test?period=5s")
11
                .log("Timer has been invoked")
12
                .pollEnrich("file:inputdirectory/input?delete=true")
13
                .to("file:outputdirectory/output");
14
    }
15
}
16

          



Create application-dev.yml, application-tst.yml, application-prod.yml, and move the route configurations specific to the environments (dev, tst, prod) to the respective YML files.

application-dev.yml

YAML
 




xxxxxxxxxx
1


 
1
server:
2
  port: 8081
3

          
4
routeStart: timer:dev?period=5s
5
routeFrom: file:dev/input?delete=true
6
routeTo: file:dev/output


application-tst.yml 

YAML
 




xxxxxxxxxx
1


 
1
server:
2
  port: 8081
3

          
4
routeStart: timer:test?period=5s
5
routeFrom: file:tst/input?delete=true
6
routeTo: file:tst/output


application-prod.yml

YAML
 




xxxxxxxxxx
1


 
1
server:
2
  port: 8081
3

          
4
routeStart: timer:prod?period=5s
5
routeFrom: file:prd/input?delete=true
6
routeTo: file:prd/output



Reference the values from the YML file in the code as below:

Java
 




x


 
1
package com.demo.camelspringboot.route;
2

          
3
import org.apache.camel.builder.RouteBuilder;
4
import org.springframework.stereotype.Component;
5

          
6
@Component
7
public class CamelRoute extends RouteBuilder {
8
    @Override
9
    public void configure() throws Exception {
10
        from("{{routeStart}}")                  //Referenced from yml
11
                .log("Timer has been invoked")
12
                .pollEnrich("{{routeFrom}}")    //Referenced from yml
13
                .to("{{routeTo}}");             //Referenced from yml
14
    }    
15
}
16

          



Create input directories specific to the environment as shown:

Edit the Run configuration of the Spring Boot application and provide the Active Profile as dev and start the application.


Notice that the file is deleted from the input directory of the dev folder and copied to the output directory as per the configuration.

Similarly, modify the Run configuration and set the Active profile as tst and prod. Notice that the file is deleted from the input directory of the respective environment folder and copied to the output directory as per the configuration and active profile set.


Spring Framework Spring Boot Apache Camel app

Opinions expressed by DZone contributors are their own.

Related

  • Auto Logging in Class and Method Level Using Custom Annotations in Spring Boot App
  • Spring Boot Pet Clinic App: A Performance Study
  • Aggregating REST APIs Calls Using Apache Camel
  • Improving Backend Performance Part 1/3: Lazy Loading in Vaadin Apps

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook