BackendBench
Coffee

Unravel โ€บ Java concepts โ€บ Messaging and Kafka

Spring

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.

๐Ÿ”Ž Unravel this example

At a glance

Mental model

A plumber laying pipes between tanks.

What happens, in order
  1. 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:).
  2. 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.
  3. 3onException(...) and errorHandler(deadLetterChannel(...)) define retries and where failed messages go
  4. 4Camel has hundreds of components, so most integration code is configuration of URIs rather than client library code
Remember
Watch out
Business logic inside the route DSLIgnoring component-specific redelivery semanticsNo dead-letter handlingUnbounded file or queue polling
Example (highlighted lines explain it)
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");    }}
  1. 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:

Part of a learning path

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.