Controlling number of threads in Mule - threadpool

I'm using Mule 3.3.1 Community Edition.
I have a flow that accepts HTTP requests. This runs successfully.
<flow name="TestFlow">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="8088" path="test" doc:name="HTTP" mimeType="text/plain"
encoding="UTF-8"/>
<logger level="INFO" category="hello" doc:name="Logger"/>
</flow>
The service needs to be single-threaded so that messages are handled strictly in the order in which they are received. My thought was to set maxThreadsActive=1 and maxBufferSize=100 to get my desired behavior. However, I can't get any control over threads to work.
At this point I'm just trying to get a thread profile working, regardless of the number of threads. I added a threading-profile exactly out of the current version of the Manning book Mule in Action, but Mule rejects it as "Invalid content" and won't run.
<flow name="TestFlow">
<threading-profile maxBufferSize="100" maxThreadsActive="20" maxThreadsIdle="10"
threadTTL="60000" poolExhaustedAction="RUN" />
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="8088" path="test" doc:name="HTTP" mimeType="text/plain"
encoding="UTF-8"/>
<logger level="INFO" category="hello" doc:name="Logger"/>
</flow>
I commented that out and moved up to a configuration block.
<configuration>
<default-threading-profile maxThreadsActive="20" maxBufferSize="100"
poolExhaustedAction="RUN" />
</configuration>
<flow name="TestFlow">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="8088" path="test" doc:name="HTTP" mimeType="text/plain"
encoding="UTF-8"/>
<logger level="INFO" category="hello" doc:name="Logger"/>
</flow>
Mule accepts this, but the service no longer returns; the client simply hangs waiting for a response.
How do I configure my flow so that I can control thread pool size and, once that's done, so that only one thread is available in the pool?

You need to configure the receiver-threading-profile of the HTTP connector:
<http:connector name="httpConnector">
<receiver-threading-profile maxThreadsActive="1" />
</http:connector>

Related

How to share persistent queue "Inter-app" in Mulesoft?

We are trying to perform the simplest publish / consume action among two different applications in the public VPC.
The publisher APP is working as expected. It generates the queue and publishes all the messages correctly.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<vm:config name="VM_Config" doc:name="VM Config" doc:id="1c2283b1-26a8-4fc9-b048-b50bbee08e62" >
<vm:queues >
<vm:queue queueName="order" queueType="PERSISTENT" />
</vm:queues>
</vm:config>
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="6f88c504-19e6-4cca-8b50-efb95b2dcbc8" >
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<flow name="sltestpqpubFlow" doc:id="23315e3e-49b0-4f61-a86c-321a2cb9c4ad" >
<http:listener doc:name="Listener" doc:id="2268dae5-2e89-45f4-a685-50602bea4205" config-ref="HTTP_Listener_config" path="/fire"/>
<vm:publish queueName="order" doc:name="Publish" doc:id="e928d591-4f4a-4d54-9390-3e69dd2520b8" config-ref="VM_Config">
<vm:content ><![CDATA[#["Message sent"]]]></vm:content>
</vm:publish>
<logger level="INFO" doc:name="Logger" doc:id="2eba63dd-15d0-4961-9c75-de8fee366caa" />
</flow>
</mule>
The listener APP on the other hand is creating its own persistent queue with the same name. Therefore, not consuming the messages published by the app mentioned above.
<mule xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd">
<vm:config name="VM_Config" doc:name="VM Config" doc:id="c9d8390d-cc35-4188-b034-70cb144f2da7">
<vm:connection >
<reconnection failsDeployment="true" >
<reconnect />
</reconnection>
</vm:connection>
<vm:queues >
<vm:queue queueName="order" queueType="PERSISTENT" />
</vm:queues>
</vm:config>
<flow name="sltestpqFlow" doc:id="1681828e-0889-4c2f-8f03-cebe7cf852cd" >
<vm:listener doc:name="Listener" doc:id="4b1a3db0-946d-4428-a7b8-b2e3aebd88fa" config-ref="VM_Config" queueName="order" transactionalAction="ALWAYS_BEGIN" transactionType="XA">
<reconnect />
</vm:listener>
<logger level="INFO" doc:name="Logger" doc:id="8efdd42a-9f73-4e07-80bd-b42cafed297f" message="Got event"/>
</flow>
</mule>
Not sure what we are missing for a single queue sharing (instead of each application having it's own)
UPDATE 02/20/2020 11:10 AM PST
We are using the VM Connector v2.0 in Mule 4
https://docs.mulesoft.com/connectors/vm/vm-reference
The VM connector only works inside the same JVM. In the case of applications deployed in CloudHub, it means inside the same application only. You can not share messages with any other applications. You need to bring your own JMS broker, installed somewhere where the applications can access it, some other message service with a connector for Mule 4, or use Anypoint MQ.

Mule with Facebook connector - OAuth access token could not be extracted from

I m using below code to authorize Facebook API. but m getting error -
Root Exception stack trace:
java.lang.IllegalArgumentException: OAuth access token could not be extracted from: {"access_token":"EAAJmNrYXQ4wBAFJIv69EuGaeUlh8LZCAUsZBLMlp8IDbyn9JLxtOsSVb3pVn6pdJb4mTzjVCrX14fBAoEuHBIOhYBSEyjPBr0l4ahOwef9l7o4BhLtzu0bACBqee7LY48OC51BDQhmea3ZANokY4KOj9HZCN6eAZD","token_type":"bearer","expires_in":5112514}
<http:listener-config name="callback" host="localhost" port="3000" doc:name="HTTP Listener Configuration" />
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="AutorizeFacebook" >
<http:listener config-ref="HTTP_Listener_Configuration" path="/facebookauthorize" doc:name="HTTP"/>
<facebook:authorize config-ref="Facebook" doc:name="Authorize" />
<set-session-variable doc:name="Save Access Token" value="\#[flowVars['OAuthAccessTokenId']]" variableName="accessTokenId"/>
<choice doc:name="Choice">
<when expression="#[flowVars['OAuthAccessTokenId']]!= null">
<logger message="Authorization Successful" level="INFO"
doc:name="Logger" />
<set-payload value="Facebook Authorization Successful"
doc:name="Set Payload" />
</when>
<otherwise>
<logger message="Authorization Failed" level="INFO" doc:name="Logger" />
<set-payload value="Facebook Authorization Failed"
doc:name="Set Payload" />
</otherwise>
</choice
</flow>
This error is due to change in Facebook API, accessToken is returned in a JSON string.
The Regex for the access token is \"access_token\":\"([^&]+?)\"
and for expiration time you have \"expires_in\":([^&]+?),")
Use DEVKIT to install connector to your studio by cloning facebook repo
Clone updated facebook connector project from
https://github.com/mulesoft/facebook-connector
import to studio as anypoint connector project
install connector to your studio and use facebook connector in your flows

How to use Choice Pattern over Soap Request in Mule ESB?

I have an endpoint accepting Soap Requests, after this endpoint, it goes to a Transform Message which generates the appropriate request to an external web service.
What I want to do is to use the Choice Pattern to decide to which external web service I must redirect.
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<cxf:configuration name="CXF_Configuration" enableMuleSoapHeaders="true" initializeStaticBusInstance="true" doc:name="CXF Configuration"/>
<ws:consumer-config name="Web_Service_Consumer" service="KarmaService" port="KarmaPort" serviceAddress="http://localhost:8080/TestingWS/Karma" wsdlLocation="http://localhost:8080/TestingWS/Karma?wsdl" doc:name="Web Service Consumer"/>
<flow name="testingChoice">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<cxf:proxy-service configuration-ref="CXF_Configuration" payload="body" doc:name="CXF"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/xml
%namespace ns0 http://karmapackage/
---
{
ns0#sayHello: {
arg0: payload.invoke.arg0
}
}]]></dw:set-payload>
</dw:transform-message>
<choice doc:name="Choice">
<when expression="#[payload]">
<logger message="Info1" level="INFO" doc:name="Logger"/>
</when>
<otherwise>
<logger message="Default" level="INFO" doc:name="Logger"/>
</otherwise>
</choice>
<ws:consumer config-ref="Web_Service_Consumer" operation="sayHello" doc:name="Web Service Consumer"/>
<logger message="Andando" level="INFO" doc:name="Logger"/>
</flow>
Right now, Choice is redirecting to Logger info, just to know what it is doing.
I don't know how to set the expression on the when condition to check if arg0 has the value choosePath1 for example.
I would appreciate any help,
Thanks in advance
Check this post, write xpath expression based on your transformed xml. Mule 3.4.0 Choice router based on presence of a node in payload using Xpath
Also check how to build xml xpath on mule documents
https://docs.mulesoft.com/mule-user-guide/v/3.8/xpath

Mule - java.lang.String cannot be cast to java.util.Map

I want to write a mule application which will read the database for unprocessed records, club them in JSON payload format and then hit a REST webservice.
I am able to read the records from the database and able to convert the database records in JSON. However, whenever I run the application I am getting following exception
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
Here is my Mule configuration XML
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<db:mysql-config name="MySQL_Configuration" host="localhost" port="3306" user="root" database="my_database_name" doc:name="MySQL Configuration"/>
<http:request-config name="HTTP_Request_Configuration" protocol="HTTPS" host="example.net" port="8000" basePath="API" doc:name="HTTP Request Configuration"/>
<flow name="cwg_clientFlow">
<poll doc:name="Poll">
<db:select config-ref="MySQL_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[SELECT * FROM cwg_ws_data WHERE SyncFlag = 0]]></db:parameterized-query>
</db:select>
</poll>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<json:object-to-json-transformer doc:name="Object to JSON" />
<logger message="JSON Payload is #[payload]" level="INFO" doc:name="Logger"/>
<http:request config-ref="HTTP_Request_Configuration" path="/cwg" method="POST" doc:name="HTTP">
<http:request-builder>
<http:query-params expression="#[payload]"/>
<http:header headerName="access_token" value="MQTgpMUmyQLt134maB6vPp6oWFgMtGsqzIlpCN74"/>
</http:request-builder>
</http:request>
<logger message="webservice response #[payload]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
I am unable to understand where it is going wrong
Please help me, I am trying this since last 2 days.
Thanks in advance
-Paresh (kendreparesh#gmail.com)
Try removing this line.
<http:query-params expression="#[payload]"/>
It should work. As your payload is Json String and you are trying to map it to Query params which expects Map. Also for POST your payload will converted to body.
expression in query-params must be a map. If you are going to pass data as query-params, why are you doing object to json? Try removing below two lines -
<json:object-to-json-transformer doc:name="Object to JSON" />
<logger message="JSON Payload is #[payload]" level="INFO" doc:name="Logger"/>

Insert SOAP web service payload into JMS using Mule

I have the following Mule flow. What I'm trying to achieve is simply to put the SOAP message into the JMS queue.
The content of the message in the JMS queue is
org.mule.module.xml.stax.ReversibleXMLStreamReader#3c7e9afa
What am I missing in the transformer?
<object-to-string-transformer name="Object_to_String" doc:name="Object to String"/>
<flow name="soapServiceFlow">
<http:listener config-ref="SOAP_JMS_HTTP_Listener_Configuration" path="/soap" doc:name="HTTP"/>
<cxf:proxy-service
configuration-ref="CXF_Configuration"
doc:name="CXF"
payload="envelope"
wsdlLocation="service.wsdl"
namespace="http://www.examples.com/wsdl/ReportService"
port="ReportPort"
service="ReportService" />
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<jms:outbound-endpoint queue="my.requests" connector-ref="Active_MQ" doc:name="JMS" transformer-refs="Object_to_String">
<jms:transaction action="NONE"/>
</jms:outbound-endpoint>
</flow>
This is a transformation error and you can simply use object-to-string-transformer to make it work:-
<object-to-string-transformer doc:name="Object to String"/>
before your JMS outbound
Before the logger, add <object-to-string-transformer doc:name="Object to String"/> for you to see the string content of the class org.mule.module.xml.stax.ReversibleXMLStreamReader#3c7e9afa