I have a issue with MongoDb Connection.I'm using a Camel with mongo,and I try connect without authentication then the connection it's ok. But, when I try connect Mongo with authentication not works.
My Processor is (it's OK) :
from("timer:aTimer?fixedRate=true&period=10s")
.setHeader(Exchange.HTTP_METHOD, constant("GET"))
.to("jetty:http://localhost:3030/getFile")
.marshal(xmlJsonFormat)
.process("camelProcessor")
.to("mongodb:mongoBean?database=eicas&collection=sales&operation=insert")
.to("log:Ok:Se guardo un registro Venta fija");
and my application-configuration without mongo auth:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camel:camelContext id="camel-client">
<camel:routeBuilder ref="vinodroute"/>
</camel:camelContext>
<bean id="mongoBean" class="com.mongodb.MongoClient">
<constructor-arg name="host" value="localhost" />
<constructor-arg name="port" value="27017" />
</bean>
<bean id="jetty" class="org.apache.camel.component.jetty8.JettyHttpComponent8"/>
<bean id="vinodroute" class="camel.venta.CamelMongoRoute"/>
<bean id="camelProcessor" class="camel.venta.CamelProcessor"/>
</beans>
The question is, How I connect mongo with autenthication?
You can use the MongoClientURI object to create the MongoClient :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camel:camelContext id="camel-client">
<camel:routeBuilder ref="vinodroute"/>
</camel:camelContext>
<bean id="mongoBean" class="com.mongodb.MongoClient">
<constructor-arg>
<ref bean="mongoClientURI" />
</constructor-arg>
</bean>
<bean id="mongoClientURI" class="com.mongodb.MongoClientURI">
<constructor-arg name="uri" value="mongodb://username:password@localhost/eicas" />
</bean>
<bean id="jetty" class="org.apache.camel.component.jetty8.JettyHttpComponent8"/>
<bean id="vinodroute" class="camel.venta.CamelMongoRoute"/>
<bean id="camelProcessor" class="camel.venta.CamelProcessor"/>
</beans>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With