You can add a component by configuring it in the Fuse Mediation Router Spring configuration file,
META-INF/spring/camel-context.xml
. To find the component, the component's
URI prefix is matched against the ID attribute of a bean
element in the
Spring configuration. If the component prefix matches a bean element ID, Fuse Mediation Router
instantiates the referenced class and injects the properties specified in the Spring
configuration.
![]() | Note |
---|---|
This mechanism has priority over auto-discovery. If the CamelContext finds a Spring bean with the requisite ID, it will not attempt to find the component using auto-discovery. |
If there are any properties that you want to inject into your component class, define them as bean properties. For example:
public classCustomComponent
extends DefaultComponent<CustomExchange
> { ...PropType
getProperty
() { ... } void setProperty
(PropType
v) { ... } }
The
get
method and the
Property
()set
method access the
value of Property
()property
.
To configure a component in Spring, edit the configuration file,
META-INF/spring/camel-context.xml
, as shown in Example 5.1.
Example 5.1. Configuring a Component in Spring
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <package>RouteBuilderPackage
</package> </camelContext> <bean id="component-prefix
" class="component-class-name
"> <property name="property
" value="propertyValue
"/> </bean> </beans>
The bean
element with ID
component-prefix
configures the
component-class-name
component. You can inject properties
into the component instance using property
elements. For
example, the property
element in the preceding example would
inject the value, propertyValue
, into the
property
property by calling
set
on the
component.Property
()
Example 5.2 shows an example of how to configure
the Fuse Mediation Router's JMS component by defining a bean element with ID equal to jms
.
These settings are added to the Spring configuration file,
camel-context.xml
.
Example 5.2. JMS Component Spring Configuration
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <package>org.apache.camel.example.spring</package></camelContext> <bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerURL" value="vm://localhost?broker.persistent=false&broker.useJmx=false"/>
</bean> </property> </bean> </beans>
The | |
The bean element with ID, | |
JMS is just a wrapper for a messaging service. You must specify the concrete
implementation of the messaging system by setting the | |
In this example, the concrete implementation of the JMS messaging service is
Apache ActiveMQ. The |