Apache Camel consumers initiate message processing in routes via the from() endpoint. They fall into two primary categories: event-driven and polling.
Core Classifications
Camel officially recognizes two consumer types—event-driven and polling—each suited to different message sources.
| Type | Description | Mechanism |
|---|---|---|
| Event-Driven | Reacts immediately to incoming events or invocations. No periodic checks. | External push (e.g., JMS) or internal calls (e.g., direct). Uses transport-provided threads. |
| Polling | Camel actively queries the endpoint at set intervals. | Scheduled checks via ScheduledExecutorService. Configurable delay/initialDelay. |
Event-Driven Consumers
These handle real-time messages without polling overhead. Examples include JMS (queue/topic events), HTTP/Netty (request triggers), and in-VM options like direct/SEDA.
- Direct: Synchronous, blocking calls within the same CamelContext—like method invocation.
- SEDA: Asynchronous queuing with backpressure control (bounded queue).
Example:
from("direct:start") // Event-driven: waits for producerTemplate.sendBody()
.log("Processed: ${body}");
Polling Consumers
Ideal for batch sources like files or databases. Camel polls periodically, ensuring ordered processing.
- Uses fixed delays; supports repeat/repeatAttempt options.
- Examples: file (watches directories), FTP/IMAP (remote checks).
Example:
from("file:input?delay=5000&noop=true") // Polls every 5s
.to("log:output");
Special Cases: In-VM Consumers
Direct and SEDA are event-driven subtypes for route chaining:
- Direct: Sync, single-context.
- SEDA: Async queue.
They differ from transport-based event-driven (e.g., JMS) by lacking external brokers but share passive reception.
When to Use Each
- Event-Driven: Low-latency, continuous streams (pub/sub, APIs).
- Polling: Reliable pulls from passive sources (files, legacy systems).
This covers Camel's consumer landscape for effective route design.
Leave a Reply