首页 > 解决方案 > 呼叫调解器超时后继续序列调解

问题描述

端点可以有三种超时配置。永远不要超时、丢弃或出错。我迫切需要在超时后继续流程。有没有办法做到这一点?故障处理程序(onError 序列)不是此问题的理想解决方案。想象一下有八个呼叫中介的编排,我必须创建八个序列并将彼此设置为故障。这将很快使碳应用程序膨胀,使代码不可读并增加部署时间。

标签: wso2wso2esbwso2ei

解决方案


基本上,在任何给定时间,端点的状态都可以是以下之一。

  1. 积极的
  2. 暂停
  3. 暂停
  4. 离开

当端点处于“超时”状态时,它将继续尝试接收消息,直到一条消息成功或达到最大重试设置。如果达到最大值,则端点被标记为“暂停”。如果一条消息成功,则端点被标记为“活动”。

如果您需要根据端点超时配置在获得端点超时时继续中介流,您可以使用 responseAction 中的故障选项。

然后,只要端点超时,就会触发故障序列(如果您已经定义了自定义故障序列,否则使用默认故障序列)。如果您需要继续调解流程并且根据现有实现,您可以在自定义序列中定义所需的调解逻辑,并在故障序列中调用该序列,如下所示。

    <?xml version="1.0" encoding="UTF-8"?>
<sequence name="customFaultSequence" xmlns="http://ws.apache.org/ns/synapse">
    <!-- Log the message at the full log level with the ERROR_MESSAGE and the ERROR_CODE-->
    <log level="full">
         <property name="MESSAGE" value="Executing default 'fault' sequence"/>
         <property expression="get-property('ERROR_CODE')" name="ERROR_CODE" xmlns:ns="http://org.apache.synapse/xsd"/>
         <property expression="get-property('ERROR_MESSAGE')" name="ERROR_MESSAGE" xmlns:ns="http://org.apache.synapse/xsd"/>
    </log>
    <sequence key="afterTimeoutEndpointSequence"/>
</sequence>

示例代理服务:

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="TestProxy" startOnLoad="true" statistics="disable" trace="disable"    transports="http,https">
   <target faultSequence="customFaultSequence">
      <inSequence>
               <endpoint>
                  <address uri="http://run.mocky.io/v3/51c11e65-55a7-47e5-ba38-1d86e8e5d7ea?mocky-delay=45000ms">
                     <timeout>
                        <duration>2</duration>
                        <responseAction>fault</responseAction>
                     </timeout>
                  </address>
               </endpoint>
           <respond/>
      </inSequence>
   <description/>
</proxy>

推荐阅读