簡體   English   中英

在Mule流中使用SQL結果變量

[英]Use an SQL result variable in a Mule flow

我有2條查詢的Mule流。 第一個簡單地驗證用戶名是否重復。

做這樣的事情:從user_tests中選擇COUNT(*)個總數,其中username =#[json:username] AND test_message_title =#[json:test_message_title]

如果TOTAL = 0,第二個將執行INSERT。

現在,我想在同一流程內的選擇中使用變量“ TOTAL”。 我該怎么做?

嘗試#[TOTAL = 0],嘗試#[variable:TOTAL = 0]和其他許多方法,但無法使其正常工作。

編輯:我做了一個Java組件,從有效載荷中檢索“ 0”或任何數字。 如何做出選擇表達式進行比較?

在選擇表達式中嘗試使用Integer.valueOf(message.payload)= 0,但我得到了InvalidExpressionException。

這是我的整個流程:

<flow name="ADMIN_INSERT_TEST_FILE" doc:name="ADMIN_INSERT_TEST_FILE">
    <ajax:servlet-inbound-endpoint channel="/admin/save_test_message" responseTimeout="10000" doc:name="Ajax"/>
    <set-variable variableName="#['saved_payload']" value="#[payload]" doc:name="Save original payload"/>
    <jdbc:outbound-endpoint exchange-pattern="request-response" queryKey="validate_test_name" queryTimeout="-1" connector-ref="ExtendedRoutingConnector" doc:name="validate duplicated test name">
        <jdbc:query key="validate_test_name" value="SELECT count(*) AS TOTAL FROM user_tests WHERE username = #[json:username] AND test_message_title = #[json:test_message_title]"/>
    </jdbc:outbound-endpoint>
    <logger message="#[message.payload[0].TOTAL]" level="INFO" category="Total" doc:name="Logger"/>
    <choice doc:name="Choice">
        <when expression="#[message.payload[0].TOTAL == 0]">
            <processor-chain>
                <set-payload value="#[variable:saved_payload]" doc:name="Save Payload"/>
                <jdbc:outbound-endpoint exchange-pattern="request-response" queryKey="insert_user_test_message" queryTimeout="-1" connector-ref="ExtendedRoutingConnector" doc:name="insert user test message">
                    <jdbc:query key="insert_user_test_message" value="INSERT INTO user_tests (username, test_message_title, user_test_message) VALUES (#[json:username], #[json:test_message_title], #[json:message])"/>
                </jdbc:outbound-endpoint>
            </processor-chain>
        </when>
        <otherwise>
            <processor-chain>
                <logger message="Name #[json:test_message_title] already exists" level="INFO" doc:name="Logger"/>
            </processor-chain>
        </otherwise>
    </choice>
</flow>

提前致謝。

使用MEL:

#[message.payload[0].TOTAL == 0]

這將從SELECT查詢返回的第一行中檢索TOTAL列的值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM