LibraryLink ToToggle FramesPrintFeedback

Adding Components to the Camel Context

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.


Where the preceding code can be explained as follows:

1

Before you can add a JMS component to the CamelContext instance, you must create a JMS connection factory (an implementation of javax.jms.ConnectionFactory). In this example, the JMS connection factory is implemented by the FUSE Message Broker class, ActiveMQConnectionFactory. The broker URL, vm://localhost, specifies a broker that is co-located in the same Java Virtual Machine (JVM) as the router. The broker library automatically instantiates the new broker when you try to send it a message.

2

Add a JMS component named test-jms to the CamelContext instance. This example uses a JMS componenet with the auto-acknowledge option set to true. This implies that messages received from a JMS queue will automatically be acknowledged (receipt confirmed) by the JMS component.