WSO2 ESB将HTTP 404视为网络错误

时间:2014-07-01 21:51:34

标签: wso2 wso2esb

我有两个端点。我希望它们能够平衡流量,并充当故障转移机制。说故障转移我的意思是,当一个端点没有响应时(目标服务由于任何原因而关闭),第二个端点将占用所有流量。我使用以下配置:

<send>
    <endpoint>
        <loadbalance algorithm="org.apache.synapse.endpoints.algorithms.RoundRobin">
            <endpoint name="bsz2_mock_ep1">
                <address uri="http://10.16.105.197:8080/bsz2_mock"/>
            </endpoint>
            <endpoint name="bsz2_mock_ep2">
                <address uri="http://10.16.105.198:8080/bsz2_mock"/>
            </endpoint>
        </loadbalance>
    </endpoint>
</send>

在这种情况下,当其中一个目标JBoss实例关闭时,所有请求都会传递给第二个请求,这是可以的。

问题是,当JBoss实例启动时,在应用程序启动之前,它会回复HTTP 404.在这种情况下,ESB会生成类似Unexpected response received. HTTP response code : 404 HTTP status : Not Found exception : First Element must contain the local name, Envelope , but found html的错误消息。我想让loadbalance端点前进并尝试下一个端点,因为它是针对连接失败错误而做的。

我尝试指定HTTP协议违规(101506)和响应处理失败(101510)错误代码,将端点标记为已暂停,并将其标记为暂停(请参阅文档:http://wso2.com/library/articles/wso2-enterprise-service-bus-endpoint-error-handling/

<endpoint xmlns="http://ws.apache.org/ns/synapse" name="bsz2_mock_ep2">
   <http uri-template="http://10.16.105.198:8080/bsz2_mock" method="post">
      <suspendOnFailure>
         <errorCodes>101506,101510,101503,101504</errorCodes>
         <initialDuration>1000</initialDuration>
         <progressionFactor>1.2</progressionFactor>
         <maximumDuration>5000</maximumDuration>
      </suspendOnFailure>
      <markForSuspension>
         <retriesBeforeSuspension>0</retriesBeforeSuspension>
         <retryDelay>1000</retryDelay>
      </markForSuspension>
   </http>
</endpoint>

<endpoint xmlns="http://ws.apache.org/ns/synapse" name="bsz2_mock_ep2">
   <http uri-template="http://10.16.105.198:8080/bsz2_mock" method="post">
      <suspendOnFailure>
         <initialDuration>1000</initialDuration>
         <progressionFactor>1.2</progressionFactor>
         <maximumDuration>5000</maximumDuration>
      </suspendOnFailure>
      <markForSuspension>
         <errorCodes>101506,101510,101503,101504</errorCodes>
         <retriesBeforeSuspension>0</retriesBeforeSuspension>
         <retryDelay>1000</retryDelay>
      </markForSuspension>
   </http>
</endpoint>

我正在使用带有NHttp传输的WSO2 ESB 4.8.1(而不是默认的传递)。

如何配置ESB以满足我的要求?

1 个答案:

答案 0 :(得分:0)

可以使用[1]

中给出的配置来实现该要求

在[2]

中找到给定方案的ESB控制台

[1]

<definitions xmlns="http://ws.apache.org/ns/synapse">
   <proxy name="loadbalance"
          transports="https http"
          startOnLoad="true"
          trace="disable">
      <description/>
      <target>
         <inSequence onError="myfault">
            <send>
               <endpoint>
                  <loadbalance algorithm="org.apache.synapse.endpoints.algorithms.RoundRobin">
                     <endpoint name="e1">
                        <address uri="http://localhost:9001/services/SimpleStockQuoteService"/>
                     </endpoint>
                     <endpoint name="e2">
                        <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                     </endpoint>
                     <endpoint name="e3">
                        <address uri="http://localhost:9003/services/SimpleStockQuoteService"/>
                     </endpoint>
                  </loadbalance>
               </endpoint>
            </send>
         </inSequence>
      </target>
   </proxy>
   <sequence name="myfault">
      <log level="custom">
         <property name="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"  value="Log sequence hit"/>
      </log>
      <drop/>
   </sequence>
</definitions>

[2]

[2015-02-01 14:36:20,988]  INFO - CarbonAuthenticationUtil 'admin@carbon.super [-1234]' logged in at [2015-02-01 14:36:20,987+0530]
[2015-02-01 14:37:23,553]  INFO - TimeoutHandler This engine will expire all callbacks after : 120 seconds, irrespective of the timeout action, after the specified or optional timeout
[2015-02-01 14:37:23,563]  WARN - ConnectCallback Connection refused or failed for : localhost/127.0.0.1:9001
[2015-02-01 14:37:23,567]  WARN - EndpointContext Endpoint : e1 will be marked SUSPENDED as it failed
[2015-02-01 14:37:23,568]  WARN - EndpointContext Suspending endpoint : e1 - current suspend duration is : 30000ms - Next retry after : Sun Feb 01 14:37:53 IST 2015
[2015-02-01 14:37:23,568]  WARN - LoadbalanceEndpoint AnonymousEndpoint Detect a Failure in a child endpoint : Endpoint [e1]
[2015-02-01 14:37:23,570]  WARN - ConnectCallback Connection refused or failed for : localhost/127.0.0.1:9000
[2015-02-01 14:37:23,570]  WARN - EndpointContext Endpoint : e2 will be marked SUSPENDED as it failed
[2015-02-01 14:37:23,571]  WARN - EndpointContext Suspending endpoint : e2 - current suspend duration is : 30000ms - Next retry after : Sun Feb 01 14:37:53 IST 2015
[2015-02-01 14:37:23,571]  WARN - LoadbalanceEndpoint AnonymousEndpoint Detect a Failure in a child endpoint : Endpoint [e2]
[2015-02-01 14:37:23,573]  WARN - ConnectCallback Connection refused or failed for : localhost/127.0.0.1:9003
[2015-02-01 14:37:23,573]  WARN - EndpointContext Endpoint : e3 will be marked SUSPENDED as it failed
[2015-02-01 14:37:23,574]  WARN - EndpointContext Suspending endpoint : e3 - current suspend duration is : 30000ms - Next retry after : Sun Feb 01 14:37:53 IST 2015
[2015-02-01 14:37:23,574]  WARN - LoadbalanceEndpoint AnonymousEndpoint Detect a Failure in a child endpoint : Endpoint [e3]
[2015-02-01 14:37:23,574]  WARN - LoadbalanceEndpoint Loadbalance endpoint : AnonymousEndpoint - no ready child endpoints
[2015-02-01 14:37:23,575]  INFO - LogMediator XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX = Log sequence hit