java - MongoDB 身份验证和 Apache Camel 的问题

标签 java spring mongodb maven apache-camel

我遇到 MongoDb Connection 问题。我正在使用带有 mongo 的 Camel,我尝试在没有身份验证的情况下进行连接,然后连接正常。但是,当我尝试使用身份验证连接 Mongo 时,它不起作用。

我的处理器是(没问题):

 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");

和我的没有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>

问题是,我如何将 mongo 与身份验证连接起来?

最佳答案

您可以使用 MongoClientURI 对象来创建 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>

关于java - MongoDB 身份验证和 Apache Camel 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49289435/

相关文章:

c# - 使用并行写入 MongoDB 时出错

java - 如何将 Actor 放在彼此之上?

java - 问题 Android Studio 1.0.2 : Fatal Exception: main Process java. lang.NullPointerException

java - NameNotFoundException 将 JNDI 数据源映射到本地名称

java - Spring Security XML 配置与 Java 配置

java - Hazelcast MBean 丢失

ruby-on-rails - 为什么我的 mongoDB 托管 mongoid.yml 的 uri 设置无法正常工作?

java - 定制生产者消费者

java - Multi-Tenancy 应用程序的数据源

mongodb - MongoDB 文档中 "Dynamic schema supports fluent polymorphism"的含义