0

我有 2 个 mule 应用程序在一台机器上运行,其中应用程序 A 向应用程序 B 发送获取请求,应用程序 B 连接到外部 http 应用程序以获取信息。基本上应用程序 B 是一个重定向应用程序,它在一天内多次抛出连接超时异常 (java.net.SocketTimeoutException)。根据我的观察,每当应用程序(B)空闲一段时间,然后如果它收到一个请求,它就会抛出第一个请求的连接超时,同时连接到出站 http 端点上的外部服务器并且后续请求工作正常。这个仅在我无权进行调试的一个环境中发生,并且我在任何其他环境中都没有遇到此问题,尽管还有两个其他环境具有相同的确切设置。

在调试问题时,感谢任何帮助/建议/指导。代码

<flow name="Main" >
        <https:inbound-endpoint exchange-pattern="request-response"
            host="${http.listenHost}" port="${support-1.0.https.port}"
            path="${service.root}"  encoding="UTF-8"
             doc:name="HTTP" connector-ref="HTTPSConnector">
            <!-- NB: SECURITY TURNED OFF BY DEFAULT AS YOU WILL NEED TO ADD RECORDS 
                TO THE DATABASE IN ORDER TO USE THIS -->
            <!-- <mule-ss:http-security-filter realm="mule-realm"/> -->
        </https:inbound-endpoint>

        <custom-interceptor class="xyz.BasicLogger">
            <spring:property name="outermost" value="true" />
        </custom-interceptor>
        <set-session-variable variableName="operation" value="#[message.inboundProperties['http.method']]" doc:name="Operation"/>

        <set-variable variableName="_logging.text" value="Incoming Payload" doc:name="Logging" />
        <component doc:name="Payload Logger">
            <spring-object bean="idPayloadLogger" />
        </component>

        <set-session-variable variableName="http.status"
            value="200" doc:name="HTTP Status" />

        <flow-ref name="Cache" doc:name="Cache"/>

        <http:response-builder status="#[sessionVars['http.status']]" contentType="application/json" doc:name="HTTP Response Builder">
            <http:header name="consumerTransId" value="#[sessionVars['tx.id']]"/>
            <http:header name="http.status" value="#[sessionVars['http.status']]"/>
            <http:header name="Content-Type" value="application/json;charset=utf-8"/>
        </http:response-builder>

    </flow>
    <flow name="Cache">
        <expression-transformer expression="#[payload]" doc:name="Create key for cache"/>
        <custom-interceptor doc:name="PayloadCache"    class="xyz.ehcache.PayloadCache"/>
        <flow-ref name="GetResult" doc:name="GetResult"/>
    </flow>

    <sub-flow name="GetResult">
        <choice doc:name="Choice">
            <when expression="sessionVars.operation =='GET'">
                <processor-chain doc:name="GET">
                    <set-variable variableName="_logging.calloutName " value="Registry GET" doc:name="_logging.calloutName "/>
                    <component doc:name="Java"><spring-object bean="idTimerLogger"/></component>
                    <http:outbound-endpoint exchange-pattern="request-response" host="${registry.host}" port="${registry.port}"
                     path="${registry.path}/#[message.inboundProperties.'http.relative.path']?#[message.inboundProperties.'http.query.string']" method="GET" doc:name="HTTP" responseTimeout="10000"/>
                    <component doc:name="Java"><spring-object bean="idTimerLogger"/></component>
                </processor-chain>

            </when>
            <when expression="sessionVars.operation =='DELETE'">
                <processor-chain doc:name="DELETE">
                    <set-variable variableName="_logging.calloutName " value="Registry DELETE" doc:name="_logging.calloutName "/>
                    <component doc:name="Java"><spring-object bean="idTimerLogger"/></component>
                    <http:outbound-endpoint exchange-pattern="request-response" host="${registry.host}" port="${registry.port}" path="${registry.path}/#[message.inboundProperties.'http.relative.path']?#[message.inboundProperties.'http.query.string']"
                     method="DELETE" doc:name="HTTP"/>
                    <component doc:name="Java"><spring-object bean="idTimerLogger"/></component>
                </processor-chain>
            </when>
            <otherwise>
                <processor-chain doc:name="Unsupported Verb">
                    <set-variable variableName="_error.code" value="2" doc:name="Error code"/>
                    <custom-transformer class="xyz.eai.utility.transformation.ErrorMessageTransformer" doc:name="Java"/>
                    <json:object-to-json-transformer doc:name="Object to JSON"/>
                </processor-chain>
            </otherwise>
        </choice>
        <object-to-string-transformer doc:name="Object to String"/>
    </sub-flow>

</mule>

错误是`

Exception stack is:
1. connect timed out (java.net.SocketTimeoutException)
  java.net.PlainSocketImpl:-2 (null)
2. The host did not accept the connection within timeout of 2000 ms (org.apache.commons.httpclient.ConnectTimeoutException)
  org.apache.commons.httpclient.protocol.ReflectionSocketFactory:155 (null)
3. Failed to route event via endpoint: DefaultOutboundEndpoint{endpointUri=http://xyz.ca.com:8080/search?param1=xyz&param2=true, connector=HttpConnector
{
  name=connector.http.mule.default
  lifecycle=start
  this=59c02565
  numberOfConcurrentTransactedReceivers=4
  createMultipleTransactedReceivers=true
  connected=true
  supportedProtocols=[http]
  serviceOverrides=<none>
}
,  name='endpoint.http.xyz.com.8080.search.param1.xyz.param2.true', mep=REQUEST_RESPONSE, properties={isActive=true, http.method=GET, exceptionOnMessageError=true, param1=xyz}, transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0}, deleteUnacceptedMessages=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8, disableTransportTransformer=false}. Message payload is of type: GetMethod (org.mule.api.transport.DispatchException)
  org.mule.transport.http.HttpClientMessageDispatcher:151 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transport/DispatchException.html)`
################3

在我的应用程序 B 中向出站 http 端点添加了一个直到成功的循环,如果我单独访问它,它就可以工作。但是,当应用程序 A 尝试与应用程序 B 通信时,甚至在应用程序 B 尝试连接到外部服务器并返回响应之前,应用程序 A 上的 http 出站端点正在抛出org.mule.api.transport.DispatchException with message : Failed to route event via endpoint: DefaultOutboundEndpoint{endpointUri=https://application-b/xyz, connector=HttpsConnector,并且当应用程序 B 完成重试并尝试发送返回对应用程序 A 的响应,得到错误:org.mule.transport.http.HttpsMessageProcessTemplate: Exception sending http response after error: Connection has been shutdown: javax.net.ssl.SSLException: java.net.SocketException: Software caused connection abort: socket write error

4

1 回答 1

0

您需要 在 HTTP/HTTPS 连接器上使用untilSuccess

<until-successful maxRetries="5" synchronous="true" doc:name="Until Successful">
            <http:request config-ref="HTTP_Request_Configuration" path="/test" method="POST" doc:name="HTTP"/>
        </until-successful>
于 2017-03-03T05:28:43.540 回答