Unravel โบ Java concepts โบ Messaging and Kafka
Apache Camel integration routes
Apache Camel connects systems with routes: take a message from one endpoint (file, queue, HTTP, database), transform and route it, and deliver it to another.
At a glance
A plumber laying pipes between tanks.
- 1Extend RouteBuilder and write from("file:inbox").unmarshal().json().filter(...).to("jms:queue:orders")Endpoints are URIs with a component prefix (file:, kafka:, http:, sftp:, jms:).
- 2Each message travels as an Exchange with a body, headers and propertiesProcessors and beans transform it; choice().when(...).otherwise() routes by content; split() and aggregate() break up and combine messages.
- 3onException(...) and errorHandler(deadLetterChannel(...)) define retries and where failed messages go
- 4Camel has hundreds of components, so most integration code is configuration of URIs rather than client library code
- Camel hides the transport, which makes it easy to miss that file polling, redelivery and transactions follow component-specific rules
- Keep routes short and readable and move business logic into beans
- At start, each from(...) creates a consumer on a thread pool, and the steps after it are compiled into a processor pipeline
public class OrderRoutes extends RouteBuilder { @Override public void configure() { onException(Exception.class).maximumRedeliveries(3).handled(true).to("jms:queue:orders.dlq"); from("file:inbox?include=.*\\.json") .unmarshal().json(JsonLibrary.Jackson, Order.class) .filter(simple("${body.total} > 0")) .to("jms:queue:orders"); }}- line 1 uses RouteBuilder, the core of Apache Camel integration routes
Read the full explanation (about 1 min)
Apache Camel connects systems with routes: take a message from one endpoint (file, queue, HTTP, database), transform and route it, and deliver it to another. It implements the classic enterprise integration patterns with a fluent Java DSL.
A mental model
A plumber laying pipes between tanks. Each pipe has a start and an end (endpoints), and fittings in between (filters, transformers, splitters) shape what flows through.
How it works
Extend RouteBuilder and write from("file:inbox").unmarshal().json().filter(...).to("jms:queue:orders"). Endpoints are URIs with a component prefix (file:, kafka:, http:, sftp:, jms:).
Each message travels as an Exchange with a body, headers and properties. Processors and beans transform it; choice().when(...).otherwise() routes by content; split() and aggregate() break up and combine messages.
onException(...) and errorHandler(deadLetterChannel(...)) define retries and where failed messages go.
Camel has hundreds of components, so most integration code is configuration of URIs rather than client library code.
Going deeper
Camel hides the transport, which makes it easy to miss that file polling, redelivery and transactions follow component-specific rules. Read the component page for each endpoint you use.
Keep routes short and readable and move business logic into beans. Long chains of inline lambdas are untestable.
Test with AdviceWith to replace real endpoints with mocks and assert the messages that arrive.
Under the hood
At start, each from(...) creates a consumer on a thread pool, and the steps after it are compiled into a processor pipeline. Each step is a Processor called in turn with the same Exchange; asynchronous endpoints continue the pipeline in a callback instead of blocking the thread.
Common mistakes
- Business logic inside the route DSL.
- Ignoring component-specific redelivery semantics.
- No dead-letter handling.
- Unbounded file or queue polling.
How Unravel recognises it
When you paste code, Unravel looks for these signs of apache camel integration routes. Spotting them yourself is a good habit when you read unfamiliar code:
- Annotations:
@Consume@EndpointInject@BeanInject - Types:
RouteBuilderCamelContextProducerTemplateConsumerTemplateDefaultCamelContextAdviceWithCamelSpringBootRunnerCamelTestSupportRoutesBuilderAggregationStrategyExchangeBuilderMockEndpointFluentProducerTemplate
Part of a learning path
- Scheduled jobs, batch and integration ยท previous: Spring Integration (channels and flows) ยท next: SFTP and file transfer clients
Related concepts
Frequently asked questions
What is Apache Camel integration routes?
Apache Camel connects systems with routes: take a message from one endpoint (file, queue, HTTP, database), transform and route it, and deliver it to another. It implements the classic enterprise integration patterns with a fluent Java DSL.
What are the most common mistakes with Apache Camel integration routes?
Business logic inside the route DSL. Ignoring component-specific redelivery semantics. No dead-letter handling. Unbounded file or queue polling.
How can I see Apache Camel integration routes in real code?
Paste your own Java into Unravel and it will point out where apache camel integration routes appears, explain how it works at the detail level you choose, and draw the flow of the code around it.