我正在尝试创建一个事务单元,它发送一个RESTful HTTP帖子并将这些数据插入表中。
虽然我有一个本地序列的onError处理程序,但是当我禁用与我的端点的连接时,而不是使'send'中介失败会使端点处于SUSPENDED状态。然后它继续跳过发送并仅插入数据。此外,我的自定义failureSequence抱怨我不在交易中,即使它是在'我'调用<transaction action="new"/>
虽然我已阅读文档并了解进入SUSPEND是失败端点的默认行为,但我实际上需要更多控制权。我想在失败时触发自己的序列(或接收一些特定的HTTP响应代码)并调用<transaction action="rollback"/>
为清楚起见,我序列的相关部分如下:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="csvToDatabaseRollback">
<log level="custom">
<property name="text" value="Rolling back transaction"/>
</log>
<transaction action="rollback"/>
<!-- rollback any other state, here -->
</sequence>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="csvRow2Pc" onError="csvToDatabaseRollback">
<transaction action="new"/>
<log level="full">
<property name="State" value="Iteration"/>
</log>
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
<log level="custom">
<property name="text" value="Calling rest-endpoint"/>
</log>
<send>
<endpoint>
<address uri="http://localhost:80/spotify" format="pox"/>
</endpoint>
</send>
<log level="custom">
<property name="text" value="After HTTP POST"/>
</log>
<dbreport useTransaction="true">
<connection>
....
</connection>
<statement>
<sql>
<![CDATA[ insert into file values (?, ?, ?)]]></sql>
<parameter xmlns:ns2="http://org.apache.synapse/xsd" xmlns:ns="http://org.apache.synapse/xsd" xmlns:sec="http://secservice.samples.esb.wso2.org" expression="//line/col_one/text()" type="VARCHAR"/>
<parameter xmlns:ns2="http://org.apache.synapse/xsd" xmlns:ns="http://org.apache.synapse/xsd" xmlns:sec="http://secservice.samples.esb.wso2.org" expression="//line/col_two/text()" type="VARCHAR"/>
<parameter xmlns:ns2="http://org.apache.synapse/xsd" xmlns:ns="http://org.apache.synapse/xsd" xmlns:sec="http://secservice.samples.esb.wso2.org" expression="//line/col_three/text()" type="VARCHAR"/>
</statement>
</dbreport>
<log level="custom">
<property name="text" value="Before tx commit"/>
</log>
<transaction action="commit"/>
</sequence>
日志包含:
[2013-10-25 15:09:40,117] WARN - ConnectCallback Connection refused or failed for : localhost/127.0.0.1:80
[2013-10-25 15:09:40,116] INFO - LogMediator text = After HTTP POST
[2013-10-25 15:09:40,129] INFO - LogMediator text = Rolling back transaction
[2013-10-25 15:09:40,129] WARN - EndpointContext Suspending endpoint : endpoint_f2e0b5550f82db317194145cb24b59f38a63ab610d8a994c - last suspend duration was : 30000ms and current suspend duration is : 30000ms - Next retry after : Fri Oct 25 15:10:10 NZDT 2013
[2013-10-25 15:09:40,121] INFO - LogMediator text = Before tx commit
[2013-10-25 15:09:40,131] INFO - LogMediator text = Rolling back transaction
[2013-10-25 15:09:40,131] ERROR - TransactionMediator Unable to rollback transaction
java.lang.IllegalStateException: This method needs a transaction for the calling thread and none exists.
Possible causes: either you didn't start a transaction,
it rolledback due to timeout, or it was committed already.
ACTIONS: You can try one of the following:
1. Make sure you started a transaction for the thread.
如果我检查数据库,则已提交行。随后的尝试很快就会跳过“发送”中介,因为它已被暂停。
理想情况下,我想发送HTTP POST,并根据REST响应而不是挂起来设置自定义路由规则。我怎么能这样做?
答案 0 :(得分:0)
当端点被挂起时,esb将调用faultsequence。在故障序列中,您可以调用任何序列。因此,它可以让您控制自定义代码。