英文:
MuleSoft's rollback database transaction problem
问题
在Mulesoft中,我尝试在try块内将数据插入到表中,数据库和try块已经配置了事务。我正在使用"on error continue"而不是"on error propagate"。但似乎当发生错误时,它不会回滚数据库事务。我的问题是,我是否必须使用"on error propagate"来回滚数据库事务?我可以使用"on error continue"来实现吗?
任何提示都将不胜感激!
<error-handler>
<on-error-continue enableNotifications="false" logException="true" doc:name="On Error Continue" doc:id="82981086-6eb6-4264-8121-d9887385788e" type="ANY">
<ee:transform doc:name="Transform Message" doc:id="d3fd89de-ddcf-4991-9c20-5e5132bbb1cd">
<ee:message>
</ee:message>
<ee:variables>
<ee:set-variable variableName="insertDatabaseFailed"><![CDATA["true"]]></ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-continue>
</error-handler>
英文:
In mulesoft I try to insert payload into tables inside try block, database and try block are configured with transaction already. I am using on Error continue instead of on error propagate.
But it seems it will not rollback database transaction when error happend.
My question is do I have to have to use on error propagate for rollback database transaction?
could I use on error continue to archeive that?
Any hints will be more than welcome!
<error-handler >
<on-error-continue enableNotifications="false" logException="true" doc:name="On Error Continue" doc:id="82981086-6eb6-4264-8121-d9887385788e" type="ANY">
<ee:transform doc:name="Transform Message" doc:id="d3fd89de-ddcf-4991-9c20-5e5132bbb1cd" >
<ee:message >
</ee:message>
<ee:variables >
<ee:set-variable variableName="insertDatabaseFailed" ><![CDATA["true"]]></ee:set-variable>
</ee:variables>
</ee:transform>
</on-error-continue>
</error-handler>
答案1
得分: 1
不,在MuleSoft中的“On Error Continue”错误处理程序不支持事务回滚。该错误处理程序旨在在遇到错误时继续处理流程,而不提供任何事务回滚机制。
如果需要在遇到错误时执行事务回滚,应该使用“On Error Propagate”错误处理程序。此处理程序确保在流程处理继续之前回滚事务。
另外,关于您的后续问题:
> 我可以在MuleSoft的“On Error Continue”块中手动回滚事务吗?
似乎没有办法在“On Error Continue”块内手动回滚事务。
要全面了解MuleSoft中的XA事务,请参考XA事务文档。
还提供了一些示例(带有流程代码),演示了涉及“On Error Continue”和“On Error Propagate”错误处理程序的情况下XA事务的行为,请查看。
英文:
No, the "On Error Continue" error handler in MuleSoft does not facilitate transaction rollback. This error handler is designed to let the flow continue processing despite encountering errors, without any transaction rollback mechanism.
If you require transaction rollback upon encountering an error, you should employ the "On Error Propagate" error handler. This handler ensures that the transaction is rolled back before the flow processing continues.
Also regarding your follow-up question:
> Could I just manually rollback a transaction in MuleSoft's "On Error
> Continue" block?
There doesn't seem to be a way to do a manual transaction rollback within the "On Error Continue" block.
For a comprehensive understanding of XA transactions in MuleSoft, refer to the documentation on XA Transactions.
There are also a couple of examples provided ( with flow code ) on Using XA Transactions with Different Resources that demonstrate how XA transactions behave in scenarios involving "On Error Continue" and "On Error Propagate" error handlers, kindly check.
答案2
得分: 0
使用"on error continue"意味着你正在处理错误,所以它不会触发回滚。在事务中的错误处理方面,请查看文档的说明:
错误传播
如果"on-error-propagate"错误处理程序位于与开始事务的组件相对应的错误处理程序范围内:
在执行"on-error-propagate"范围的处理器之前,事务将被回滚。这意味着错误处理程序内部的处理器不会在事务内运行。
如果"on-error-propagate"错误处理程序位于未启动事务的元素内:
事务不会回滚,"on-error-propagate"错误处理程序内部的处理器将在事务内运行。请记住,在事务内执行时,某些范围和路由器的行为不同。
错误继续
错误已处理,事务保持活动状态,并能够提交。"on-error-continue"内部的处理器在事务内运行。
英文:
Using on error continue means that you are handling the error so it will not trigger the rollback. See what the documentation says on error handling in transactions:
> * On Error Propagate
>
> * If the on-error-propagate error handler is inside the error-handler scope corresponding to the component that began the
> transaction:
>
> The transaction is rolled back before executing the processors of the on-error-propagate scope. This means that the processors inside
> the error handler do not run within the transaction.
>
> * If the on-error-propagate error handler is inside an element that did not start the transaction:
>
> The transaction is not rolled back and the processors inside the on-error-propagate error handler run within the transaction.
> Remember that some scopes and routers behave differently when
> executing within a transaction.
>
> * On Error Continue
>
> The error is handled, the transaction remains active and is able to commit. The processors inside the on-error-continue run within the
> transaction.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论