Integration / Apache Camel Interview Questions
What are Camel Components and how do you use the Timer, File, HTTP, and JMS components?
A Camel Component is the factory responsible for creating Endpoint instances for a given URI scheme. Over 300 components ship with Camel, discovered automatically via META-INF/services/org/apache/camel/component/ entries. You use a component by referencing its URI scheme in from() or to().
// Timer: trigger a route every 5 seconds
from("timer:heartbeat?period=5000")
.setBody(constant("health-check"))
.to("log:health");
// File: poll directory, move processed files
from("file:/in?move=processed&delay=2000")
.to("file:/out");
// HTTP: outbound POST with JSON body
from("direct:send")
.setHeader(Exchange.HTTP_METHOD, constant("POST"))
.setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
.to("http://api.example.com/orders");
// JMS: consume from queue, produce to topic
from("jms:queue:orders")
.to("jms:topic:order-events");All four components follow the same URI pattern: scheme:path?options. Timer and File are primarily consumer-only (from()) and producer-only respectively; HTTP and JMS support both roles. Components are thread-safe singletons in the CamelContext; the same instance creates all endpoints for its scheme.
More Related questions...