beans XML XML.
my spring XML
<?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.xsd">
<bean id="voltMongo" class="com.mongodb.MongoClient">
<constructor-arg name="host" value="localhost" />
<constructor-arg name="port" value="27017" />
</bean>
</beans>
xml
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="_route1">
<description>here is a sample which processes the subscribe the mqtt topic from broker and push into Mongo Db</description>
<from id="_from1" uri="paho:iot/test/#?brokerUrl=tcp://localhost:1883"/>
<convertBodyTo type="java.lang.String"/>
<to id="_to2" uri="mongodb:voltMongo?database=Volt&collection=dummyData&operation=insert"/>
</route>
</routes>
java- FileSystemXmlApplicationContext spring xml, bean jndi, , . . Java
CamelContext context= null;
ApplicationContext applicationContext =new FileSystemXmlApplicationContext("springconfig.xml");
JndiRegistry registry=null;
if (applicationContext != null) {
String[] beanNames=applicationContext.getBeanDefinitionNames();
if (beanNames != null) {
Map<String,String> enviroment= new HashMap<String,String>();
enviroment.put("java.naming.factory.initial", "org.apache.camel.util.jndi.CamelInitialContextFactory");
registry= new JndiRegistry(enviroment);
for (String name : beanNames) {
registry.bind(name,applicationContext.getBean(name));
}
}
}
context= new DefaultCamelContext(registry);
InputStream is = new FileInputStream(file);
RoutesDefinition routes = context.loadRoutesDefinition(is);
context.addRouteDefinitions(routes.getRoutes());
context.start();