2

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?

Tad
  • 517
  • 8
  • 30
  • Try adding a logger after the http:outbound in your flow2 and check what is the payload. – user1760178 Jun 05 '13 at 18:41
  • I have and it seems to be correct. I can't put it in this comment due to length (I'm not that experienced with StackOverflow)...is the normal thing to add it into the original message to display it? – Tad Jun 05 '13 at 18:51

2 Answers2

1

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>
FelixFang
  • 136
  • 3
0

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

<copy-properties propertyName="MULE_*"/>
Seba
  • 2,319
  • 15
  • 14
  • It worked for me with that. Can you show your new configuration with that change? – Seba Jun 05 '13 at 20:00
  • I stand partially corrected. The flow is still not succeeding...i.e., it is not giving me the result I expect, but the behavior has changed with that addition. I'm now getting to the "After queue" logging without a timeout. The resulting payload doesn't look like I expect, i.e., like it does without using the queue. Perhaps the passage through the queue is altering the format of the information? Anyway, to address your request, how does one post a subsequent configuration since they won't fit in a comment? Do you have to alter the original message? – Tad Jun 05 '13 at 20:29
  • I'll add that I don't believe the approach on Mule's site actually works for throttling. However, this has now become a learning experience. – Tad Jun 05 '13 at 21:40