2013-11-27 64 views
0

我是新的MuleESB值。我對流程沒有太多的瞭解。我無法找到適合Mule的文檔。我正嘗試使用下面的代碼從數據庫中獲取數據,但我無法獲取數據。沒有顯示錯誤,所以我不知道該怎麼辦。我的流程是否正確?我如何選擇基於哪裏條件在騾ESB

這是我的流程配置。

<?xml version="1.0" encoding="UTF-8"?> 

<mule xmlns:jdbc-ee="http://www.mulesoft.org/schema/mule/ee/jdbc" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" 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.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/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.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/jdbc http://www.mulesoft.org/schema/mule/ee/jdbc/current/mule-jdbc-ee.xsd 
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd"> 
    <jdbc-ee:postgresql-data-source name="PostgreSQL_Data_Source" user="youtilitydba" password="Youtility11" 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="selectfromdbFlow1" doc:name="selectfromdbFlow1"> 
     <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="selectdb" doc:name="HTTP"/> 
     <json:json-to-object-transformer returnClass="java.util.Map" doc:name="JSON to Object"/> 
     <jdbc-ee:outbound-endpoint exchange-pattern="one-way" queryKey="SELECT" queryTimeout="-1" connector-ref="Database" doc:name="Database"> 
      <jdbc-ee:query key="SELECT" value="select firstname,lastname,id from users where id =#[message.payload.id]"/> 
     </jdbc-ee:outbound-endpoint> 
     <response> 
      <http:response-builder status="200" contentType="application/json" doc:name="HTTP Response Builder"/> 
     </response> 
     <set-payload value="#[payload]" doc:name="Set Payload"/> 
       <echo-component doc:name="Echo"/> 
      </flow> 
</mule> 

我從捲曲客戶端這樣的

curl -H "Content-Type: application/json" -d '{"id":"5"}' http://192.168.25.24:8081/selectdb 

它不提供與響應回送請求。

我在等待下面的回覆。

{"Body":{"Datalist":{"firstname":"ff","lastname":"ggg","id":"5"}},"Status":"200"}} 

請幫我實現這個。

即使記錄聲明不打印

<logger message="message of payload#[message.payload]" level="INFO" doc:name="Logger"/> 

得到任何幫助。

回答

0

我無法完全回答你的問題,但可以告訴你幾個簡單的方法來檢查你的muleMessage。 第一和最簡單的方法是將一個腳本變壓器這樣的:

<script:transformer> 
       <script:script engine="groovy"> 
        <script:text> 
         System.out.println(payload); 
         return payload; 
        </script:text> 
       </script:script> 
</script:transformer> 

命名空間:XMLNS:腳本= 「http://www.mulesoft.org/schema/mule/scripting」

的schemaLocation :http://www.mulesoft.org/schema/mule/scriptinghttp://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd

第二個選項和更難的是將創建自定義變壓器。你需要創建一個java類,擴展AbstractMessageTransformer。然後調試項目,看看有什麼消息 希望,這將有助於

+0

thanx for replay實際上我希望從數據庫中選擇行並以json格式響應客戶端do.and哪個流程需要按照 –

0

不能得到你所面臨的問題齊全。從帖子中我可以看到幾乎沒有什麼變化。

當你正在尋找數據從Select Query變化exchange-patternJBDC:Outboundrequest-response

<jdbc-ee:outbound-endpoint exchange-pattern="request-response" queryKey="SELECT" queryTimeout="-1" connector-ref="Database" doc:name="Database"> 

背部也有是在流的末尾沒有需要<set-payload>的。由於消息中已有負載,因此這是一個冗餘聲明。

在記錄器嘗試使用#[payload],因爲它更簡單地打印您的有效載荷(從JBDC查詢響應)

關於文檔,MuleSoft網站找到有關騾子的文檔他們有最詳細的文檔最好的地方騾子的東西。

Mule User Guide and Documentation

希望這有助於。

+0

thanx重播,根據您的建議,即時消息進入流程但無法通過客戶端 *在服務中收到的消息:selectfromdbFlow1。內容是:'[{lastname = ff,*所以我設置有效載荷如上,即使它沒有傳遞到客戶端 * firstname = ff,id = 5}] * * –

+0

Upvote答案,如果他們對你有任何幫助。 – user1760178

+0

無法理解您在上述評論中的問題。 – user1760178

1

你就能更好地運用<json:json-to-object-transformer returnClass="java.lang.Object" doc:name="JSON to Object"/>http:inbound-endpoint後,並確保如果從請求和有效載荷後DB後得到的id值現在

,如果你是從你的數據庫獲取數據,並能使用打印出來使用

<logger message="message of payload #[message.payload]" level="INFO" doc:name="Logger"/> 

您可以明確地設置在下面的方式您在您的客戶端的響應分貝後記錄: -

<http:response-builder status="200" contentType="application/json" doc:name="HTTP Response Builder"> 
    <set-payload value="#[message.payload]" doc:name="Set Payload"/> 
</http:response-builder> 

,您可以從流中刪除<response/>標記,因爲您正在使用<http:response-builder/>設置您的響應有效內容