MongoDB Connector 6.3 の例 - Mule 4

操作の呼び出し

シンプルな操作 (​Insert Document​ 操作など) を呼び出す手順は、次のとおりです。

  1. Studio で ​[HTTP]​ をクリックし、​[Listener]​ 操作をキャンバスにドラッグします。

  2. パレットから ​[MongoDB]​ を選択し、[Insert Document] 操作をドラッグして、フローの ​[HTTP Listener (HTTP リスナー)]​ の右側に配置します。

  3. コネクタを設定します。これを行うには、前のセクションで作成した ​[Connector Configuration (コネクタ設定)]​ を選択し、呼び出す操作を選択して、​[Collection name (コレクション名)]​ を設定します。

  4. パレットから、​[Transform Message]​ コンポーネントを MongoDB Connector の左側にドラッグします。

  5. [Transform Message]​ をクリックして、2 つのキー-値ペアを入力します。

    %dw 2.0
    %output application/json
    ---
    {
    	name:"Peter",
    	age:"42"
    }
  6. [Mule Palette (Mule パレット)] ビューから、別の ​[Transform Message]​ コンポーネントを MongoDB Connector の右側にドラッグします。

  7. 新しい ​[Transform Message]​ をクリックして、出力を ​application/json​ に設定します。

    %dw 2.0
    output application/json
    ---
    payload

操作を呼び出す XML

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:mongo="http://www.mulesoft.org/schema/mule/mongo"
	xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
	xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns="http://www.mulesoft.org/schema/mule/core"
	xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="
	http://www.mulesoft.org/schema/mule/http
	http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
	http://www.mulesoft.org/schema/mule/ee/core
	http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
	http://www.mulesoft.org/schema/mule/core
	http://www.mulesoft.org/schema/mule/core/current/mule.xsd
	http://www.mulesoft.org/schema/mule/http
	http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
	http://www.mulesoft.org/schema/mule/ee/core
	http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
	http://www.mulesoft.org/schema/mule/mongo
	http://www.mulesoft.org/schema/mule/mongo/current/mule-mongo.xsd">

	<configuration-properties file="mule-app.properties" />
	<http:listener-config name="HTTP_Listener_config"
		doc:name="HTTP Listener config">
		<http:listener-connection host="0.0.0.0"
			port="8081" />
	</http:listener-config>
	<mongo:config name="MongoDB_Config" doc:name="MongoDB Config">
		<mongo:connection database="${database}">
			<mongo:server-addresses >
				<mongo:server-address host="${host}" port="${port}"/>
			</mongo:server-addresses>
		</mongo:connection>
    </mongo:config>

    <flow name="create-mongo-record-flow" >
        <http:listener
				  config-ref="HTTP_Listener_config" path="/create"
              doc:name="Listener" />
        <ee:transform doc:name="Set Payload and Document Content">
            <ee:message>
                <ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{
	name:"Pity",
	age:"31"
}]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <mongo:insert-document config-ref="MongoDB_Config"
               doc:name="Insert document"
               collectionName="${collection}" />
        <logger level="INFO" doc:name="Logger"
	  message="New document:  #[payload]" />
    </flow>
</mule>