在WSO2 EI 6.2中捕获端点超时

问题描述 投票:1回答:1

我在EI 6.2中有一个API,该API调用后端端点。有时此EP处于脱机状态,因此呼叫超时。我想捕获此超时并将其封装在自定义响应中,然后再将其发送回客户端。这个想法似乎很简单,但是我很难实现它。我尝试将以下部分添加到EP声明中。据我了解,action = fault属性应该使EP在请求超时(因此被错误处理程序序列捕获)时引发错误,但这种情况不会发生。有人对如何处理这种情况有任何建议吗?

谢谢。

佩德罗

我的EP:

<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="wacs_parameters.endpoint" xmlns="http://ws.apache.org/ns/synapse">
    <loadbalance algorithm="org.apache.synapse.endpoints.algorithms.RoundRobin">
        <endpoint name="WACS_CpeGm_Parameters_Master">
            <http method="GET" uri-template="http://xpto
                <suspendOnFailure>
                    <initialDuration>-1</initialDuration>
                    <progressionFactor>1.0</progressionFactor>
                </suspendOnFailure>
                <markForSuspension>
                    <retriesBeforeSuspension>0</retriesBeforeSuspension>
                </markForSuspension>
                <timeout>
                    <duration>3000</duration>
                    <action>fault</action>
                </timeout>
            </http>
        </endpoint>
    </loadbalance>
    <description/>
</endpoint>

这是请求中的日志,为清楚起见进行了编辑:

[2020-02-26 16:38:33,962] [EI-Core]  WARN - TimeoutHandler Expiring message ID : urn:uuid:8b9c9632-ef0b-423d-9827-84eee517b75d; dropping message after ENDPOINT_TIMEOUT of : 3 seconds for Endpoint [WACS_CpeGm_Parameters_Master], URI : xpto, Received through API : ClientEquipmentsAPI
[2020-02-26 16:38:41,318] [EI-Core]  WARN - ConnectCallback Connection refused or failed for : /10.217.49.10:8280
[2020-02-26 16:38:41,318] [EI-Core]  WARN - SynapseCallbackReceiver Synapse received a response for the request with message Id : urn:uuid:8b9c9632-ef0b-423d-9827-84eee517b75d But a callback is not registered (anymore) to process this response
[2020-02-26 16:40:33,967] [EI-Core]  WARN - TimeoutHandler Expiring message ID : urn:uuid:2a928d56-cf7f-4950-a5f4-8033798e205e; dropping message after GLOBAL_TIMEOUT of : 120 seconds for Endpoint [API_ClientEquipments_Endpoint_Master], URI : xpto, Received through API : ClientEquipmentsAPI
[2020-02-26 16:41:20,394] [EI-Core]  INFO - SourceHandler Writer null when calling informWriterError
[2020-02-26 16:41:20,394] [EI-Core]  WARN - SourceHandler Connection time out after request is read: http-incoming-10 Socket Timeout : 180000 Remote Address : /127.0.0.1:53092
[2020-02-26 16:41:20,408] [EI-Core]  INFO - SourceHandler Writer null when calling informWriterError
[2020-02-26 16:41:20,408] [EI-Core]  WARN - TargetHandler Connection time out after while in state : REQUEST_DONE Socket Timeout : 180000 Remote Address : localhost/127.0.0.1:8280
[2020-02-26 16:41:20,408] [EI-Core]  WARN - SourceHandler Connection time out after request is read: http-incoming-11 Socket Timeout : 180000 Remote Address : /127.0.0.1:53093
[2020-02-26 16:41:20,409] [EI-Core]  WARN - SynapseCallbackReceiver Synapse received a response for the request with message Id : urn:uuid:2a928d56-cf7f-4950-a5f4-8033798e205e But a callback is not registered (anymore) to process this response
wso2 wso2esb wso2ei
1个回答
1
投票

因此,仅通知其他可能存在相同问题的人:当端点超时时,EI会激活故障序列。您可以在那里找到故障并进行适当处理。属性ERROR_MESSAGE详细说明错误的种类,如此处所述]

https://docs.wso2.com/display/EI640/Error+Handling

此示例序列捕获超时并返回自定义的错误代码(使用HTTP 502):

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="faultSequence_ClientEquipmentsAPI" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <switch source="get-property('ERROR_CODE')">
        <case regex="101503|101504">
            <call-template target="faultTemplate_clientEquipmentsAPI">
                <with-param name="res_messageCode" value="801"/>
                <with-param name="res_message" value="Timeout waiting answer of backend system"/>
            </call-template>
            <property name="HTTP_SC" scope="axis2" type="STRING" value="502"/>
            <respond/>
        </case>
   </switch>
</sequence>
© www.soinside.com 2019 - 2024. All rights reserved.