0
votes

I have the following flow in Mule 3.3.2:

<flow name="testFlow" processingStrategy="synchronous">
    <vm:inbound-endpoint
            connector-ref="vmConnector"
            path="in">
        <vm:transaction action="ALWAYS_BEGIN"/>
    </vm:inbound-endpoint>

    <transactional action="ALWAYS_BEGIN">
        <jdbc:outbound-endpoint
                connector-ref="jdbcConnector"
                queryKey="insertTest"
        />

        <jdbc:outbound-endpoint
                connector-ref="jdbcConnector"
                queryKey="insertTest2"
        />
        <rollback-exception-strategy/>
    </transactional>

    <vm:outbound-endpoint
            connector-ref="vmConnector"
            path="outErrorQueue">
        <vm:transaction action="ALWAYS_JOIN"/>
    </vm:outbound-endpoint>
 </flow>

What I'm trying to achieve is a jdbc transaction nested into the vm transaction: any exception inside the transactional scope should trigger rollback for the jdbc transaction, propagate to the scope of the transactional flow and trigger the default exception strategy for the vm transaction. Any exception outside of the transactional scope should just trigger the default exception strategy of the flow, of course.

Reading source for e.g. org.mule.transaction.TransactionCoordination leads me to believe that that might work, at least if transactional would accept ACTION_NOT_SUPPORTED as action (which it does not -- can I make it?).

What i get instead is

org.mule.transaction.IllegalTransactionStateException: A transaction is not available for this session, but transaction action is "Always Join"
at org.mule.execution.ValidateTransactionalStateInterceptor.execute(ValidateTransactionalStateInterceptor.java:41)
at org.mule.execution.IsolateCurrentTransactionInterceptor.execute(IsolateCurrentTransactionInterceptor.java:44)
at org.mule.execution.ExternalTransactionInterceptor.execute(ExternalTransactionInterceptor.java:52)

at the vm:outbound-endpoint.

Is there any alternative way to get what I want with Mule?

1

1 Answers

0
votes

I don't think the VM connector supports nested transactions.

I would try using XA for this use case as XA transactions can be suspended and resumed, which would happen at the boundaries of the transactional block:

<jbossts:transaction-manager />

<flow name="testFlow" processingStrategy="synchronous">
    <vm:inbound-endpoint
            connector-ref="vmConnector"
            path="in">
        <xa-transaction action="ALWAYS_BEGIN"/>
    </vm:inbound-endpoint>

    <transactional action="ALWAYS_BEGIN">
        <jdbc:outbound-endpoint
                connector-ref="jdbcConnector"
                queryKey="insertTest"
        />

        <jdbc:outbound-endpoint
                connector-ref="jdbcConnector"
                queryKey="insertTest2"
        />
        <rollback-exception-strategy/>
    </transactional>

    <vm:outbound-endpoint
            connector-ref="vmConnector"
            path="outErrorQueue">
        <xa-transaction action="ALWAYS_JOIN"/>
    </vm:outbound-endpoint>
</flow>