Spring Integration - MongoDB入站通道适配器无法正常工作

时间:2014-12-01 10:57:54

标签: spring-integration spring-data-mongodb

我已经配置了MongoDB入站通道适配器。但是,入站通道适配器未按预期工作。我尝试了出站通道适配器,并成功将一些内容写入数据库。似乎连接成功但数据检索不成功。我也没有看到任何日志。任何人都可以指出我缺少的东西吗?

  <?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:int="http://www.springframework.org/schema/integration"
        xmlns:int-jms="http://www.springframework.org/schema/integration/jms"
        xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
        xmlns:int-http="http://www.springframework.org/schema/integration/http"
        xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
            http://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms-2.0.xsd
            http://www.springframework.org/schema/integration/mongodb http://www.springframework.org/schema/integration/mongodb/spring-integration-mongodb.xsd
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http.xsd">

        <bean id="mongoDBFactory"
            class="org.springframework.data.mongodb.core.SimpleMongoDbFactory">
            <constructor-arg name="mongo">
                <bean class="com.mongodb.Mongo">
                    <constructor-arg name="host" value="localhost" />
                    <constructor-arg name="port" value="27017" />
                </bean>
            </constructor-arg>
            <constructor-arg name="databaseName" value="test" />
        </bean>

        <int-mongodb:inbound-channel-adapter
            id="mongoInboundAdapter" channel="mongoChannel" expect-single-result="true"
            query="{'_id' : '10'}" entity-class="com.test.si.prototype.model.Order"
            collection-name="orders" auto-startup="false"
            mongodb-factory="mongoDBFactory">
            <int:poller fixed-rate="1000" />
        </int-mongodb:inbound-channel-adapter>

        <int:channel id="mongoChannel" />
        <int:logging-channel-adapter id="logger"
            auto-startup="true" log-full-message="true" level="INFO" channel="mongoChannel" />

        <int:service-activator input-channel="mongoChannel"
            ref="messageListenerImpl" method="processMessage" />


        <bean id="messageListenerImpl" class="com.test.si.prototype.service.MessageListenerImpl"></bean>
    </beans>

1 个答案:

答案 0 :(得分:0)

首先,您的<int-mongodb:inbound-channel-adapter>标有auto-startup="false"。因此,在您手动start() mongoInboundAdapter之前,它不会从数据库轮询数据。

从另一方面来说,你应该明白query="{'_id' : '10'}"并不好。因为您只会从数据库中检索单个文档,并且只有它具有id == 10

您确定在orders集合中有这样的文档吗?