XML でのキー値の保存
-
Redis 名前空間を Mule 要素に追加します。
xmlns:redis="http://www.mulesoft.org/schema/mule/redis" -
Redis 名前空間によって参照される Redis スキーマの場所を追加します。
http://www.mulesoft.org/schema/mule/redis http://www.mulesoft.org/schema/mule/sfdc-composite/current/mule-redis.xsd -
HTTP 名前空間を Mule 要素に追加します。
xmlns:http="http://www.mulesoft.org/schema/mule/http"
-
HTTP 名前空間によって参照される HTTP スキーマの場所を追加します。
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd -
プロジェクトに
redis:config 要素を追加し、その属性を設定します。<redis:config name="Redis__Configuration" host="${config.host}" connectionTimeout="${config.connectionTimeout}" port="${config.port}" doc:name="Redis: Configuration"/> -
プロジェクトに
http:listener-config 要素を追加し、その属性を設定します。<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/> -
プロジェクトに空のフロー要素を追加します。
<flow name="set-flow"> </flow> -
フロー要素内に
http:listener 要素を追加します。<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="Set value HTTP endpoint"/> -
フロー要素内の
http:listener の後にredis:set を追加します。<redis:set config-ref="Redis__Configuration" key="#[payload.key]" value="#[payload.value]" doc:name="Set value for key into Redis"/> -
フロー要素内の
redis:set の後にset-payload 要素を追加します。<set-payload value="Value successfully set" doc:name="Set value response"/> -
完了すると、XML ファイルは次のようになります。
<?xml version="1.0" encoding="UTF-8"?> <mule xmlns:redis="http://www.mulesoft.org/schema/mule/redis" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" 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:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.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/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd http://www.mulesoft.org/schema/mule/redis http://www.mulesoft.org/schema/mule/redis/current/mule-redis.xsd"> <redis:config name="Redis__Configuration" host="${config.host}" connectionTimeout="${config.connectionTimeout}" port="${config.port}" doc:name="Redis: Configuration"/> <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/> <flow name="set-flow"> <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="Set value HTTP endpoint"/> <redis:set config-ref="Redis__Configuration" key="#[payload.key]" value="#[payload.value]" doc:name="Set value for key into Redis"/> <set-payload value="Successfully set value: #[payload.value] to key: #[payload.key]" doc:name="Set value response"/> </flow> </mule>
XML カスタムオブジェクトストア
このユースケースでは、Mule アプリケーションで Redis Connector をカスタムオブジェクトストアとして使用する方法を説明します。
-
Redis 名前空間を Mule 要素に追加します。
xmlns:redis="http://www.mulesoft.org/schema/mule/redis" -
Redis 名前空間によって参照される Redis スキーマの場所を追加します。
http://www.mulesoft.org/schema/mule/redis http://www.mulesoft.org/schema/mule/sfdc-composite/current/mule-redis.xsd -
HTTP 名前空間を Mule 要素に追加します。
xmlns:http="http://www.mulesoft.org/schema/mule/http" -
HTTP 名前空間によって参照される HTTP スキーマの場所を追加します。
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd -
オブジェクトストア名前空間を Mule 要素に追加します。
xmlns:os="http://www.mulesoft.org/schema/mule/os" -
オブジェクトストア名前空間によって参照されるオブジェクトストアスキーマの場所を追加します。
http://www.mulesoft.org/schema/mule/os http://www.mulesoft.org/schema/mule/os/current/mule-os.xsd -
プロジェクトに
os:config 要素を追加して、Redis Connector 種別 (クラスターまたは非クラスター) を含むように設定します。この設定は Studio でのみ可能で、XML を使用して行う必要があります (Studio のグラフィック設定はサポートされていません)。<os:config name="ObjectStore_Config"> <redis:nonclustered-connection host="${redis.host}"/> </os:config> -
プロジェクトに
os:object-store 要素を追加して、すでに作成してある設定を参照するように設定します。<os:object-store name="Object_store" config-ref="ObjectStore_Config" maxEntries="1" entryTtl="60" expirationInterval="10" expirationIntervalUnit="SECONDS"/> -
プロジェクトに
http:listener-config 要素を追加し、その属性を設定します。<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/> -
プロジェクトに空のフロー要素を追加します。
<flow name="set-flow"> </flow> -
フロー要素内に
http:listener 要素を追加します。<http:listener config-ref="HTTP_Listener_Configuration" path="/" /> -
フロー要素内で、
http:listener の後にos:store を追加して、すでに作成してあるオブジェクトストアを使用するように設定します。<os:store key="#[attributes.queryParams.key]" objectStore="Object_store" failIfPresent="true" failOnNullValue="false"> <os:value ><![CDATA[#[attributes.queryParams.value]]]></os:value> </os:store> -
完了すると、XML ファイルは次のようになります。
<?xml version="1.0" encoding="UTF-8"?> <mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:os="http://www.mulesoft.org/schema/mule/os" xmlns:redis="http://www.mulesoft.org/schema/mule/redis" 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/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/redis http://www.mulesoft.org/schema/mule/redis/current/mule-redis.xsd http://www.mulesoft.org/schema/mule/os http://www.mulesoft.org/schema/mule/os/current/mule-os.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd"> <http:listener-config name="HTTP_Listener_config"> <http:listener-connection host="0.0.0.0" port="8081" /> </http:listener-config> <os:object-store name="Object_store" config-ref="ObjectStore_Config" maxEntries="1" entryTtl="60" expirationInterval="10" expirationIntervalUnit="SECONDS"/> <os:config name="ObjectStore_Config"> <redis:nonclustered-connection host="${redis.host}"/> </os:config> <flow name="StoreFlow" > <http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/store"/> <os:store doc:name="Store" key="#[attributes.queryParams.key]" objectStore="Object_store" failIfPresent="true" failOnNullValue="false"> <os:value ><![CDATA[#[attributes.queryParams.value]]]></os:value> </os:store> </flow> </mule>