Json 如何使用Mule ESB将CUSTISE响应返回给客户端

Json 如何使用Mule ESB将CUSTISE响应返回给客户端,json,mule,mule-studio,mule-el,Json,Mule,Mule Studio,Mule El,我是mule esb的新手,但我知道其他esb模式 我的问题是我已经做了一个将数据插入数据库的示例。它工作正常,但没有给客户端任何响应,所以客户端从服务器上什么也得不到 我的示例代码是 <mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:jdbc-ee="http://www.mulesoft.o

我是mule esb的新手,但我知道其他esb模式 我的问题是我已经做了一个将数据插入数据库的示例。它工作正常,但没有给客户端任何响应,所以客户端从服务器上什么也得不到 我的示例代码是

<mule xmlns:json="http://www.mulesoft.org/schema/mule/json"
    xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:jdbc-ee="http://www.mulesoft.org/schema/mule/ee/jdbc"
    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" version="EE-3.4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="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/jdbc http://www.mulesoft.org/schema/mule/ee/jdbc/current/mule-jdbc-ee.xsd
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">

<jdbc-ee:postgresql-data-source name="PostgreSQL_Data_Source" user="youtilitydba" password="45782dfff1" url="jdbc:postgresql://localhost:5432/sample" transactionIsolation="UNSPECIFIED" doc:name="PostgreSQL Data Source"/>
    <jdbc-ee:connector name="Database" dataSource-ref="PostgreSQL_Data_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database"/>
    <flow name="insertintoDBFlow1" doc:name="insertintoDBFlow1">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP" path="httpPost"/>
        <logger message="log about input message: #[payload]" level="INFO" doc:name="Logger"/>

                <json:json-to-object-transformer doc:name="JSON to Object" returnClass="java.util.Map"></json:json-to-object-transformer>

        <jdbc-ee:outbound-endpoint exchange-pattern="one-way" queryKey="INSERT_TOKEN" queryTimeout="-1" connector-ref="Database" doc:name="Database">
            <jdbc-ee:query key="INSERT_TOKEN" value="insert into users(FirstName,lastname) values(#[message.payload.name],#[message.payload.id]);"/>
        </jdbc-ee:outbound-endpoint>
    </flow>

</mule>
当我运行这个json时,它不会给出任何响应,但我希望给出如下响应:{code>{“ResponseJSON”:{“Body”:{“Datalist”:{“Data”:“已成功插入行”}},Status”:“200”}


我将如何格式化我使用的上述格式http响应生成器,但没有类似的操作。

您需要添加一个Echo组件,将负载设置为您要查找的值,并添加一个带有
status=“200”
contentType=“application/json”
的http响应生成器

之后和
之前添加以下行


干杯


-马可

thanx a ton.我是新来的。我会建议我选择数据,我如何才能为选择创建有效负载,我们如何像java sop一样在muleesb中记录消息。我这样做是正确的,不是有效的。即使是#[payload]也可以在mule消息中打印有效负载。请尝试以下操作:
curl -H "Content-Type: application/json" -d '{"name":"kk","id":"anil"}' http://localhost:8081/httpPost
<response>
        <http:response-builder status="200" contentType="application/json" doc:name="HTTP Response Builder"/>
    </response>
    <response>
        <set-payload value="{&quot;Body&quot;:{&quot;Datalist&quot;:{&quot;Data&quot;:&quot;Successfully Rows inserted&quot;}},&quot;Status&quot;:&quot;200&quot;}}" doc:name="Set Payload"/>
    </response>
    <echo-component doc:name="Echo"/>