NullPayload for Database Query仅在包装在Transaction中时

时间:2016-07-15 21:06:26

标签: transactions mule

我有一个流程,当包装在多事务中时,它始终返回NullPayload。当我删除多事务标记时,我得到了预期的结果。这是为什么?这是代码段

<flow name="successful-flow" processingStrategy="synchronous">
    <vm:inbound-endpoint exchange-pattern="request-response" path="order-process.in" doc:name="VM"/>
    <ee:multi-transactional action="ALWAYS_BEGIN" doc:name="Transactional" >
        <foreach collection="#[message.payload]" doc:name="For Each"
        rootMessageVariableName="Original">
            <jms:outbound-endpoint queue="orders.queue"
            connector-ref="jmsConnector" doc:name="JMS - Send to Order Processing Queue">
            <jms:transaction action="JOIN_IF_POSSIBLE"/>
        </jms:outbound-endpoint>
        </foreach>
    <db:insert config-ref="ORDER_DB" doc:name="Save Orders" >
        <db:parameterized-query><![CDATA[insert into orders(PRODUCT_ID,LINE_ITEM_CODE,PRICE,LST_UPDT_TMSP) VALUES('XXT665,'TP',20.99,'09/09/2010')]]></db:parameterized-query>
    </db:insert>
    </ee:multi-transactional>
    <response>
        <db:select config-ref="ORDER_DB" doc:name="Database" transactionalAction="ALWAYS_JOIN">
            <db:parameterized-query><![CDATA[select count(*) from orders]]></db:parameterized-query>
        </db:select>
    </response>
    <catch-exception-strategy doc:name="Order Processing Exception">
        <logger
            message="Error  during  flow - #[message] :: Exception::= #  [exception.summaryMessage]"
            level="ERROR" doc:name="Logger" />
    </catch-exception-strategy>
</flow>

1 个答案:

答案 0 :(得分:0)

我的不好,以前的交易不会完成并且已经提交。 select查询的默认transactionalAction是JOIN_IF_POSSIBLE,这意味着我将在插入和提交数据之前读取数据。简单修复如下:

import collections
from itertools import zip_longest
import operator

from tabulate import tabulate

def parsed_list(lst):
    width = max(len(item) for item in lst)
    return ['{key} {value}'.format(key=key.ljust(width), value=value)
            for key, value in sorted(
                collections.Counter(lst).items(),
                key=operator.itemgetter(1), reverse=True)]

a = parsed_list(['Black Cat', 'Black Dog', 'Black Mouse'])
b = parsed_list(['Bird', 'Bird', 'Parrot'])
c = parsed_list(['Eagle', 'Eagle', 'Eagle', 'Hawk'])

print(tabulate(zip_longest(a, b, c), headers=["Column 1", "Column 2", "Column 3"]))

# Output:
# Column 1       Column 2       Column 3
# -------------  -------------  -------------
# Black Mouse 1  Bird        2  Eagle       3
# Black Dog   1  Parrot      1  Hawk        1
# Black Cat   1