The essential difference between components and endpoints is that, when configuring a component, you provide concrete connection details (for example, hostname and IP port), whereas, when specifying an endpoint URI, you provide abstract identifiers (for example, queue name and service name). It is also possible to define multiple endpoints for each component. For example, a single message broker (represented by a component) can support connections to multiple different queues (represented by endpoints).
The relationship between an endpoint and a component is established through a
URI prefix. Whenever you add a component to a CamelContext
instance, the
component gets associated with a particular URI prefix (specified as the first argument to
the CamelContext.addComponent()
method). Endpoint URIs that start with
that prefix are then automatically parsed by the associated component.
Example 1.2 shows the outline of the standalone main()
method, highlighting the details of
how to add a JMS component to the CamelContext
instance.
Example 1.2. Adding a Component to the CamelContext
public final class CamelJmsToFileExample { ... public static void main(String args[]) throws Exception { CamelContext context = new DefaultCamelContext(); // Add components to the CamelContext. ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");context.addComponent("test-jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
// Add routes to the CamelContext. // ... (not shown) // Start the context. context.start(); // End of main thread. } }
Where the preceding code can be explained as follows:
Before you can add a JMS component to the | |
Add a JMS component named |