Как написать в MongoDB с помощью весенней интеграции - PullRequest
0 голосов
/ 06 сентября 2018

Я читаю из Rabbit MQ и пишу в MongoDB с использованием пружинных интеграций XML. Я могу читать из Rabbit MQ, но не могу написать в 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-amqp="http://www.springframework.org/schema/integration/amqp"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xmlns:int-stream="http://www.springframework.org/schema/integration/stream"
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="http://www.springframework.org/schema/integration/amqp 
    http://www.springframework.org/schema/integration/amqp/spring-integration-amqp.xsd
    http://www.springframework.org/schema/integration
    http://www.springframework.org/schema/integration/spring-integration.xsd
    http://www.springframework.org/schema/integration/stream
    http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd
    http://www.springframework.org/schema/rabbit
    http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd">


<bean id="connectionFactory"
  class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
    <constructor-arg value="localhost"/>
        <property name="username" value="guest"/>
        <property name="password" value="guest"/>
</bean>

<int-amqp:inbound-channel-adapter channel="fromRabbit"
    queue-names="promo-queue" connection-factory="connectionFactory" />


 <int:object-to-string-transformer input-channel="fromRabbit"
    output-channel="mychanneloutput" charset="UTF-8">
</int:object-to-string-transformer> 

<int:channel id = "mychanneloutput"/>
<int:channel id="fromRabbit">
    <int:interceptors>
        <int:wire-tap channel="loggingChannel" />
    </int:interceptors>
</int:channel>

<int:logging-channel-adapter id="loggingChannel" log-full-message="true" level="INFO" />

<rabbit:template id="amqpTemplate" connection-factory="connectionFactory" mandatory="true" /> <!-- for nacks -->

<rabbit:admin connection-factory="connectionFactory" />

<rabbit:queue name="promo-queue" />

<rabbit:direct-exchange name="prmo-exchange">
    <rabbit:bindings>
        <rabbit:binding queue="promo-queue" key="promo-queue" />
    </rabbit:bindings>
</rabbit:direct-exchange>   


<mongo:db-factory id="mongoDbFactory" dbname="test" />

<int-mongodb:outbound-channel-adapter id="mongoAdapter"  />

Мои вопросы следующие: 1. Как инициализировать mongoDBFactory с хостом, портом и другими деталями подключения. 2. Как записать данные в MongoDB, используя адаптер исходящих каналов, используя XML.

1 Ответ

0 голосов
/ 06 сентября 2018

Вы можете найти образец MongoDB в этом репо: https://github.com/spring-projects/spring-integration-samples/tree/master/basic/mongodb

Хост, порт и другие параметры фабрики соединений являются атрибутами упомянутого компонента <mongo:db-factory>. Больше информации в документации: https://docs.spring.io/spring-data/mongodb/docs/2.0.9.RELEASE/reference/html/#mongo.mongo-db-factory-xml

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...