我對騾很新,需要縫合一些微服務來實現業務目標。在這方面,我的服務是基於REST的,並具有JSON負載。下面是我的配置(到目前爲止使用),以便從mule調用服務。如何使用來自Mule Flow的json有效載荷發佈到REST API?
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:json="http://www.mulesoft.org/schema/mule/json" 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/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="9001" doc:name="HTTP Listener Configuration"/>
<http:request-config name="HTTP_Request_Configuration" host="10.208.165.126" port="8080" basePath="/ingestion" doc:name="HTTP Request Configuration"/>
<flow name="ingestionsampleFlow" >
<http:listener config-ref="HTTP_Listener_Configuration" path="/ingestion/" doc:name="HTTP"/>
<set-payload doc:name="Set Payload" value="#[payload.user]"/>
<!-- <json:json-to-object-transformer returnClass="java.util.Map" mimeType="application/json" doc:name="JSON to Object"/>
<http:request config-ref="HTTP_Request_Configuration" path="esb" method="POST" doc:name="HTTP"/>
-->
<!-- <http:inbound-endpoint doc:name="HTTP" exchange-pattern="request-response" contentType="application/json" host="10.208.165.126" port="8080"/> -->
<http:outbound-endpoint exchange-pattern="request-response" host="10.208.165.126" port="8080" method="POST" contentType="application/json" doc:name="HTTP" path="esb"/>
<logger message="2-->#[payload]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
我的服務託管在10.208.165.126:8080/ingestion/esb;但這甚至不會影響我的服務。此服務具有以下格式的有效載荷:{「user」:「saurabh」}
請幫助我完成配置並幫助實現我的目標。
感謝哥們,它真的有用,只有1個小問題,json輸入值是硬編碼的,我可以讓它動態。我共享的輸入是指定格式的樣本 –
是的,我硬編碼它僅用於示例目的:)您可以使用數據映射器/數據編織或任何傑克遜庫來構造您的json數據並使其成爲您當前的有效載荷之前WS –
請幫我拿個樣品 –