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
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Java 21 Is a Major Step for Java: Non-Blocking IO and Upgraded ZGC
  • Microservices With Apache Camel and Quarkus
  • Aggregating REST APIs Calls Using Apache Camel
  • Spring Boot Microservices + Apache Camel: A Hello World Example

Trending

  • Agentic AI for Automated Application Security and Vulnerability Management
  • Ethical AI in Agile
  • How the Go Runtime Preempts Goroutines for Efficient Concurrency
  • Transforming AI-Driven Data Analytics with DeepSeek: A New Era of Intelligent Insights
  1. DZone
  2. Coding
  3. Frameworks
  4. Getting Started With Apache Camel and Java

Getting Started With Apache Camel and Java

Learn the basics of how to create a Maven-based standalone Apache Camel project using the Java DSL with this straightforward tutorial.

By 
Bennet Schulz user avatar
Bennet Schulz
·
Oct. 09, 17 · Tutorial
Likes (10)
Comment
Save
Tweet
Share
18.2K Views

Join the DZone community and get the full member experience.

Join For Free

some days ago, a friend of mine told me it would be very hard to start with apache camel as a java developer because the documentation is missing or very hard to find.

i know there are some other tutorials out there, but some of them are outdated or contain too much content for a simple getting-started guide. therefore, i decided to write this post to help other developers starting with apache camel and java.

this post describes how to create a new maven based standalone apache camel project using the java dsl. standalone means it's a plain java application and not integrated with a spring application, an osgi bundle, or something like that.

creating a camel project via console

you can use the following snippet to generate an apache camel project with a small sample routing logic using the java dsl.

mvn archetype:generate 
-dgroupid=com.schulz.bennet 
-dartifactid=camel-start-java 
-darchetypegroupid=org.apache.camel.archetypes 
-darchetypeartifactid=camel-archetype-java 
-dinteractivemode=false

creating a camel project via intellij

just in case you don't like the console that much, you can use the intellij wizard as well. open intellij and click on file -> new -> project... -> maven . now enable the create from archetype checkbox and select org.apache.camel.archetypes:camel-archetype-java .

image title in the next step, you have to type your groupid and artifactid. you can also change the version if you want to:

image title

understanding the sample project

in the sample which comes with the maven archetype, there are two classes: mainapp and myroutebuilder . the main app looks like this:

image title

as you can see, it's a plain java class which contains a main() method as every java se project does. in addition to a java se project, there is also a main object in the main() method. this main object is a helper class which comes with the camel core dependency (part of your maven pom.xml). it can be used to boot up camel and keep it running more easily.

note: it's also possible to create a camelcontext on your own instead of using the main object for it, but i recommend using the main object for it because you don't have to add code to keep the jvm up and running. the main object takes care of it and will run as long as you don't terminate the current jvm.

you have to use this main object to add camel routes to it. a route is a class which contains integration logic like inputs, transformations, endpoints and so on. it's comparable to a graph which has exactly one source and one sink.

the camel route in this sample is named myroutebuilder .

image title

a route class has to extend the routebuilder class. in addition to that, it has to override a configure() method which contains the routing logic. in this example, it contains a logic which reads files from src/main/data by using the file component. (see: apache camel file connector ).

note: components can be configured by adding it in http query parameter style. in this example, the 'noop' configuration means that the files in the src/main/data directory should not be moved or deleted.

as you can see in the intellij snippet, processing steps are added to the route by using a builder api starting with a from() method call. this from() call contains the file component described before. in the next processing step there is a choice() method call followed by when() and otherwise() calls. these two method calls take the output of the file component in the processing step before and take a look into the file itself by using the xpath component. this component parses the input files and searches for /person/city hierarchy in the input file. if it's part of the file and the city is london, another component will log "uk message" and will write the whole file to target/messages/uk . otherwise it will log "other message" and write it to target/messages/others .

that's it. just a small tutorial on how to get started with apache camel and java and an explanation of the sample project which comes with the apache camel java dsl maven archetype. i hope it helps some developers to get started which apache camel and java more easily.

Apache Camel Java (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • Java 21 Is a Major Step for Java: Non-Blocking IO and Upgraded ZGC
  • Microservices With Apache Camel and Quarkus
  • Aggregating REST APIs Calls Using Apache Camel
  • Spring Boot Microservices + Apache Camel: A Hello World Example

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!