Question

I have a back end service that I need to throttle access to. I'm trying to use the approach described here: http://blogs.mulesoft.org/synchronous-and-asynchronous-throttling-2/

I started with a simple pass through flow that receives a SOAP request and forwards it. When I hit this using the SOAPUI utility, I get the expected response in a second or two.

<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>

If I then move the outbound call to a separate flow and add in the request-reply block, the behavior changes. I get no response back (nor do I get the "After queue" message from the logger) and SOAPUI eventually times out.

<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>

The throttling behavior works as I see the delays if I pull out the call to the back end service. But I can't get it to work with the service call there.

What am I missing?

Was it helpful?

Solution

I found that the message's payload will be "ArrayList" after "request-reply". so i add a java component to split it, then the result will be corrected.

@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();
}

the completed flow is:


    <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>

OTHER TIPS

Try adding the following before the HTTP outbound endpoint in flow2:

<copy-properties propertyName="MULE_*"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top