2

我有一个需要限制访问的后端服务。我正在尝试使用此处描述的方法:http: //blogs.mulesoft.org/synchronous-and-asynchronous-throttling-2/

我从一个简单的传递流开始,它接收一个 SOAP 请求并转发它。当我使用 SOAPUI 实用程序点击它时,我会在一两秒内得到预期的响应。

<http:connector name="httpConnector" doc:name="HTTP\HTTPS">
    <receiver-threading-profile maxThreadsActive="1" maxBufferSize="100" />
</http:connector>

<jms:activemq-connector name="amqConnector" brokerURL="tcp://localhost:61616" specification="1.1" doc:name="AMQ" />

<flow name="Flow1" processingStrategy="synchronous" doc:name="Flow1">

    <http:inbound-endpoint exchange-pattern="request-response" 
        host="localhost" port="8088" path="test" doc:name="HTTP" 
        mimeType="text/xml" encoding="UTF-8" connector-ref="httpConnector"/>

    <http:outbound-endpoint
        address="http://dnbdirect-api.dnb.com/DnBAPI-11"
        exchange-pattern="request-response" doc:name="HTTP" mimeType="text/xml"/>
</flow>

如果我随后将出站呼叫移动到单独的流并添加请求-回复块,则行为会发生变化。我没有得到回复(我也没有从记录器中得到“队列后”消息),并且 SOAPUI 最终超时。

<http:connector name="httpConnector" doc:name="HTTP\HTTPS">
    <receiver-threading-profile maxThreadsActive="1" maxBufferSize="100" />
</http:connector>

<jms:activemq-connector name="amqConnector" brokerURL="tcp://localhost:61616" specification="1.1" doc:name="AMQ" />

<flow name="Flow1" processingStrategy="synchronous" doc:name="Flow1">

    <http:inbound-endpoint exchange-pattern="request-response" 
        host="localhost" port="8088" path="test" doc:name="HTTP" 
        mimeType="text/xml" encoding="UTF-8" connector-ref="httpConnector"/>

    <message-properties-transformer  doc:name="Message Properties">
        <add-message-property key="AMQ_SCHEDULED_DELAY" value="5000"/>
    </message-properties-transformer>

    <logger message="Before queue" level="INFO"/>

    <request-reply>
        <jms:outbound-endpoint queue="request" connector-ref="amqConnector"></jms:outbound-endpoint>
        <jms:inbound-endpoint queue="response" connector-ref="amqConnector"></jms:inbound-endpoint>
    </request-reply>  

    <logger message="After queue" level="INFO"/>
</flow>

<flow name="flow2" doc:name="Flow2">

    <jms:inbound-endpoint queue="request" connector-ref="amqConnector" doc:name="JMS"/>

    <http:outbound-endpoint 
        address="http://dnbdirect-api.dnb.com/DnBAPI-11" 
        exchange-pattern="request-response" doc:name="HTTP" mimeType="text/xml" />
</flow>

如果我取消对后端服务的调用,则限制行为会起作用,因为我会看到延迟。但我无法让它与那里的服务调用一起工作。

我错过了什么?

4

2 回答 2

1

我发现在“request-reply”之后消息的有效负载将是“ArrayList”。所以我添加了一个java组件来拆分它,然后结果将被纠正。

@Override
public Object onCall(MuleEventContext eventContext) throws Exception {
    MuleMessage message = eventContext.getMessage();

    //int groupSize = message.getCorrelationGroupSize();
    //System.out.println("############# correlationGroupSize: " + groupSize);

    Object payload = message.getPayload();
    if (payload != null && payload instanceof ArrayList) {
        //message.setPayload(((ArrayList)payload).get(0));
        return ((ArrayList)payload).get(0);
    }

    return message.getPayload();
}

完成的流程是:


    <message-properties-transformer  doc:name="Message Properties">
        <add-message-property key="AMQ_SCHEDULED_DELAY" value="10000"/>
    </message-properties-transformer>

    <request-reply storePrefix="mainFlow">
        <jms:outbound-endpoint queue="request" connector-ref="amqConnector" doc:name="JMS"></jms:outbound-endpoint>
        <jms:inbound-endpoint queue="response" connector-ref="amqConnector" doc:name="JMS"></jms:inbound-endpoint>
    </request-reply>
    <component class="com.neusoft.fx.JmsMessageTransformer" doc:name="Java"/>
    <message-properties-transformer doc:name="Set Content Type">
        <delete-message-property key="Content-type" />
        <add-message-property key="Content-Type" value="text/xml"/>
    </message-properties-transformer> 
    <logger message="----- LOGGER ----- after #[groovy:message.toString()]" level="INFO" doc:name="Logger" />
</flow>
于 2013-08-07T06:32:25.630 回答
0

尝试在 flow2 中的 HTTP 出站端点之前添加以下内容:

<copy-properties propertyName="MULE_*"/>
于 2013-06-05T19:21:51.870 回答