Rollback strategy with maxRedeliveryAttempts and VM inbound configured does not redeliver messages - exception

My flow looks like the below, I expect the message to be redelivered 2 times and then the
Redelivery is exhaused SAD
logger to be printed. But after the component throws the exception the re delivery mechanism does not kick in
<vm:connector name="VM" validateConnections="true" doc:name="VM" />
<flow name="TriggerFlow" >
<http:listener config-ref="Orders_HTTP_Listener_Configuration" path="/rollback" allowedMethods="GET" doc:name="1080/rollback" />
<vm:outbound-endpoint exchange-pattern="request-response" path="txFlow" doc:name="VM" connector-ref="VM" responseTimeout="60000">
</vm:outbound-endpoint>
</flow>
<flow name="TxFlow" >
<vm:inbound-endpoint exchange-pattern="request-response" path="txFlow" doc:name="case1" connector-ref="VM" responseTimeout="60000">
<xa-transaction action="ALWAYS_BEGIN"/>
</vm:inbound-endpoint>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy"><![CDATA[throw new RuntimeException();]]></scripting:script>
</scripting:component>
<rollback-exception-strategy maxRedeliveryAttempts="3" doc:name="Rollback Exception Strategy">
<logger message="Will rollback #[payload]" level="INFO" doc:name="Logger"/>
<on-redelivery-attempts-exceeded>
<logger message="Redelivery is exhaused SAD " level="INFO" doc:name="Logger"/>
</on-redelivery-attempts-exceeded>
</rollback-exception-strategy>
</flow>

I finally got the answer after speaking with MuleSoft. The updated flow should look like the below, both the VM's should be one-way and the processing strategy of the TxFlow should be synchronous. If the VM is request-reponse then it behaves more like a flow-ref with no queue involved and hence no redelivery ...

Related

Mule rethrow exception from catchexception

How do exception can be rethrow from catch-exception-strategy in mule.
Tried with below flows and after an exception from "flowdemo" errorhandling, it doesn't go to errorhandling of mdemoflow. it executes logger that is place after flow-ref.
<mule ....>
<sub-flow name="exceFlow">
<logger level="ERROR" doc:name="Logger"/>
<expression-component doc:name="Expression"><![CDATA[throw new java.lang.IllegalArgumentException('bad arg');]]></expression-component>
<validation:is-true expression="false" doc:name="Validation"/>
<scripting:component doc:name="Script">
<scripting:script engine="Groovy"><![CDATA[throw new java.lang.IllegalArgumentException('bad arg')]]></scripting:script>
</scripting:component>
<logger level="INFO" doc:name="Logger"/>
</sub-flow>
<flow name="flowdemo" processingStrategy="synchronous">
<expression-component doc:name="Expression"><![CDATA[flowVars.dummy = flowVars.fake.test]]></expression-component>
<catch-exception-strategy doc:name="Catch Exception Strategy" >
<flow-ref name="exceFlow" doc:name="Flow Reference"/>
</catch-exception-strategy>
</flow>
<flow name="mdemoFlow" processingStrategy="synchronous">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="3" timeUnit="MINUTES"/>
<logger level="INFO" doc:name="Logger"/>
</poll>
<flow-ref name="flowdemo" doc:name="flowdemo"/>
<logger level="INFO" doc:name="Logger"/>
<catch-exception-strategy doc:name="Catch Exception Strategy">
<logger message="test logging in error" level="ERROR" doc:name="Logger"/>
<logger level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
</flow>
</mule>
flowdemo which is flow ( Not a subflow) and has its own catch Exception Stratergy(So it is being handled by the demo flow itself). Thread started from main flow (mdemoFlow) which is calling other flow Via flowRef hence it is back to the mainFlow to complete the thread which is expected(Irrespective of flow processing strategy). If you want to handled all the exception in the main flow itself. Please use the below config ( Make the flowdemo as subflow), so by default any exception happen in its associated subflow will be back to its main flow to handle the same.
<sub-flow name="flowdemo" >
<expression-component doc:name="Expression"><![CDATA[flowVars.dummy = flowVars.fake.test]]></expression-component>
</sub-flow>
<flow name="mdemoFlow" processingStrategy="synchronous">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="3" timeUnit="MINUTES"/>
<logger level="INFO" doc:name="Logger"/>
</poll>
<flow-ref name="flowdemo" doc:name="flowdemo"/>
<logger level="INFO" doc:name="Logger" message="***final logger***"/>
<catch-exception-strategy doc:name="Catch Exception Strategy">
<logger message="test logging in error" level="ERROR" doc:name="Logger"/>
<logger level="INFO" doc:name="Logger"/>
<flow-ref name="exceFlow" doc:name="Flow Reference"/>
</catch-exception-strategy>
</flow>
<sub-flow name="exceFlow">
<logger level="ERROR" doc:name="Logger"/>
<logger level="INFO" doc:name="Logger"/>
</sub-flow>
To make Exception strategy as Global. You can use global exception strategy and call the same via reference Exception strategy. Please refer the link for more details https://docs.mulesoft.com/mule-user-guide/v/3.7/reference-exception-strategy

Choice Exception Strategy doesn't work in Mule

Below is a exception strategy part of the flow
<choice-exception-strategy doc:name="Choice Exception Strategy">
<catch-exception-strategy when="exception.causedBy(java.sql.BatchUpdateException)" doc:name="SQL deadlock error">
<logger message="SQL EXCEPTION - RETRYING BATCH PROCESS"
level="ERROR" doc:name="Payload Logger" category="asi_user"/>
<set-variable variableName="Exception" value="User" doc:name="Exception Type"/>
<flow-ref name="Reload_Batch" doc:name="Retry Batch Results"/>
</catch-exception-strategy>
<catch-exception-strategy when="exception.causedBy(com.microsoft.sqlserver.jdbc.SQLServerException)" doc:name="SQL error">
<logger message="SQL EXCEPTION - RETRYING BATCH PROCESS"
level="ERROR" category="asi_user" doc:name="Payload Logger" />
<set-variable variableName="Exception" value="User" doc:name="Exception Type"/>
<flow-ref name="Reload_Batch" doc:name="Retry Batch Results"/>
</catch-exception-strategy>
<catch-exception-strategy doc:name="Unexpected errors">
<logger message="UNEXPECTED EXCEPTION - SEND EMAIL NOTIFICATION"
level="ERROR" category="asi_user" doc:name="Payload Logger" />
<set-payload value="#[exception.cause.message]" doc:name="Set Payload"/>
<flow-ref name="Send_Error_Notification" doc:name="Send Email Notification"/>
</catch-exception-strategy>
</choice-exception-strategy>
Even when a java.sql.BatchUpdateException is thrown from the flow, the control goes to the final exception strategy "Unexpected Errors", it doesn't go to SQL deadlock error
Am I missing anything to make it work.
Could any please help me with this to make it work.I'm using is Mule server 3.4.0 EE
Thank you in advance
It is the problem with your expression in the when
Try it the following way.
<catch-exception-strategy when="#[exception.causedBy(java.sql.BatchUpdateException)]" doc:name="SQL deadlock error">
Hope this helps.

Mule Proxy Service can't find definition in namespace

I've set up a few proxy services in mule, but still learning. For some reason this flow doesn't work when the namespace and service name should be correct. Anybody see my error?
Thanks for the time
<flow name="UPCFlow1" doc:name="UPCFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="4040" path="upc" doc:name="HTTP"/>
<cxf:proxy-service namespace="http://searchupc.com/" service="GetProduct" payload="envelope" wsdlLocation="http://www.searchupc.com/service/UPCSearch.asmx?WSDL" doc:name="SOAP" port="UPCSearchSoap"/>
<http:outbound-endpoint address="http://www.searchupc.com/supc/service/UPCSearch.asmx"
exchange-pattern="request-response" doc:name="HTTP"/>
</flow>
This is from the stack trace
INFO 2012-10-12 11:06:44,739 [main] org.mule.module.launcher.application.DefaultMuleApplication: App 'upc' never started, nothing to dispose of
Exception in thread "main" org.mule.module.launcher.DeploymentInitException: ServiceConstructionException: Could not find definition for service {http://searchupc.com/}GetProduct.
There is an issue in your configuration: the service name is "UPCSearch" not "GetProduct".
This works:
<flow name="UPCFlow1" doc:name="UPCFlow1">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="4040" path="upc" doc:name="HTTP" />
<cxf:proxy-service namespace="http://searchupc.com/"
service="UPCSearch" payload="envelope"
wsdlLocation="http://www.searchupc.com/service/UPCSearch.asmx?WSDL"
doc:name="SOAP" port="UPCSearchSoap" />
<http:outbound-endpoint
address="http://www.searchupc.com/supc/service/UPCSearch.asmx"
exchange-pattern="request-response" doc:name="HTTP" />
</flow>

Mule ESB 3.3 "All" flow messes up payload for downstream components

EDIT: Simplified question.
Why on earth, the file written is garbage (binary serilized data) instead of the payload that was set in the Groovy component? This only happens if there is an "All" Flow component.
Flow:
XML:
<file:connector name="OutputFile" autoDelete="true" streaming="true" validateConnections="true" doc:name="File" writeToDirectory="#{systemProperties['user.home']}"/>
<flow name="AllProblemFlow1" doc:name="AllProblemFlow1">
<vm:inbound-endpoint exchange-pattern="one-way" path="in" doc:name="VM"/>
<all doc:name="All">
<processor-chain>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy">
<scripting:text><![CDATA[return payload + 1]]></scripting:text>
</scripting:script>
</scripting:component>
</processor-chain>
<processor-chain>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy">
<scripting:text><![CDATA[return payload + 2]]></scripting:text>
</scripting:script>
</scripting:component>
</processor-chain>
</all>
<logger message="All payload: #[payload]" level="INFO" doc:name="Logger"/>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy">
<scripting:text><![CDATA[return "new payload"]]></scripting:text>
</scripting:script>
</scripting:component>
<file:outbound-endpoint responseTimeout="10000" connector-ref="OutputFile" doc:name="File" outputPattern="output.txt" path="#{systemProperties['user.home']}"/>
</flow>
This is very tricky: the all message processor changes the very nature of the in-flight Mule message from a MuleMessage to a MuleMessageCollection. Changing the payload on a MuleMessageCollection is basically ineffective.
You need to forcefully replace the current MuleMessageCollection with a brand new MuleMessage. Use the following code for your last Groovy component:
<scripting:text><![CDATA[
return new org.mule.DefaultMuleMessage("new payload", muleContext)
]]></scripting:text>

Execute action after all split messages have been processed

I have a Mule 3.3.0 flow which splits a file into records. I need to execute an action (stored procedure) AFTER ALL records have finished processing.
The problem is that sometimes the action gets executed before all records have been processed by Mule. I think this is due to the fact that Mule process stuff in parallel, which is great, so sometimes the final action gets called too early.
If I set the flow as synchronous things appear to work, but I'm not taking advantage of parallel execution.
I think I could also use a Foreach scope (haven't tried) but I guess that stuff will still not be parallelized.
Is there a way to "wait" until all records finish processing?
I'm attaching a very simple flow which exhibits this behaviour. If you run it you will see that the loggers don't print stuff in order. Actually, the "DONE" message gets logged before the rest.
The flow processes a simple csv file auntil it matches a field with value "end". There is a choice component which loggs "DONE" when such field is found. The rest of the fields simply get logged.
Any help will be greatly appreciated.
Flow:
Flow xml
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"
xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:file="http://www.mulesoft.org/schema/mule/file"
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" version="CE-3.3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
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 ">
<file:connector name="inputFileConnector" autoDelete="true"
streaming="false" validateConnections="true" doc:name="File" fileAge="60000"
readFromDirectory="#{systemProperties['user.home']}" />
<flow name="flow1" doc:name="flow1" processingStrategy="synchronous">
<file:inbound-endpoint path="#{systemProperties['user.home']}"
responseTimeout="10000" doc:name="Input File" fileAge="100"
connector-ref="inputFileConnector">
<file:filename-regex-filter pattern="input.csv"
caseSensitive="false" />
</file:inbound-endpoint>
<byte-array-to-string-transformer
doc:name="Byte Array to String" />
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy">
<scripting:text><![CDATA[return payload.split('\n');]]></scripting:text>
</scripting:script>
</scripting:component>
<collection-splitter doc:name="Collection Splitter" />
<choice doc:name="Choice">
<when expression="#[groovy:payload != 'end']">
<processor-chain>
<logger message="." level="INFO" doc:name="Process"/>
<vm:outbound-endpoint path="toFlow2" doc:name="VM"/>
</processor-chain>
</when>
<otherwise>
<processor-chain>
<logger message="|||| DONE" level="INFO" doc:name="DONE"/>
</processor-chain>
</otherwise>
</choice>
</flow>
<flow name="flow2" doc:name="flow2" >
<vm:inbound-endpoint path="toFlow2" doc:name="VM"/>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy">
<scripting:text><![CDATA[return payload.split(',');]]></scripting:text>
</scripting:script>
</scripting:component>
<collection-splitter doc:name="Collection Splitter" />
<logger message="|||||| #[payload]" level="INFO" doc:name="Logger"/>
<vm:outbound-endpoint path="toFlow3" doc:name="VM"/>
</flow>
One option is to use a collection-aggregator to act as an accumulator, blocking the final flow action until all the messages have been processed. The trick is that the collection-splitters will set up a correlation group size that is only good for either the number of lines in the file or the number of columns in the file. But we want to accumulate until all columns of all lines have been processed. The solution consists in computing first this value (ie total number of expected messages) and overriding whatever correlation group size had been calculated the collection-splitters with the total value.
Here is how I've done this (you'll note that I replaced all Groovy snippets with more Mule-3-esque MEL expressions):
<file:connector name="inputFileConnector" autoDelete="true"
streaming="false" validateConnections="true" fileAge="60000"
readFromDirectory="#{systemProperties['user.home']}" />
<flow name="flow1" processingStrategy="synchronous">
<file:inbound-endpoint path="#{systemProperties['user.home']}"
responseTimeout="10000" fileAge="100"
connector-ref="inputFileConnector">
<file:filename-regex-filter pattern="input.csv"
caseSensitive="false" />
</file:inbound-endpoint>
<byte-array-to-string-transformer />
<set-session-variable variableName="expectedMessageCount"
value="#[org.mule.util.StringUtils.countMatches(message.payload, '\n') + org.mule.util.StringUtils.countMatches(message.payload, ',') - 1]" />
<expression-transformer expression="#[message.payload.split('\n')]" />
<collection-splitter enableCorrelation="IF_NOT_SET" />
<set-property propertyName="MULE_CORRELATION_GROUP_SIZE"
value="#[sessionVars.expectedMessageCount]" />
<choice>
<when expression="#[message.payload != 'end']">
<processor-chain>
<logger message="." level="INFO" />
<vm:outbound-endpoint path="toFlow2" />
</processor-chain>
</when>
<otherwise>
<processor-chain>
<logger message="|||| END" level="INFO" />
</processor-chain>
</otherwise>
</choice>
</flow>
<flow name="flow2">
<vm:inbound-endpoint path="toFlow2"/>
<expression-transformer expression="#[message.payload.split(',')]" />
<collection-splitter />
<set-property propertyName="MULE_CORRELATION_GROUP_SIZE"
value="#[sessionVars.expectedMessageCount]" />
<logger message="|||||| #[message.payload]" level="INFO"/>
<vm:outbound-endpoint path="toFinalizer" />
<vm:outbound-endpoint path="toFlow3" />
</flow>
<flow name="finalizer">
<vm:inbound-endpoint path="toFinalizer" />
<collection-aggregator />
<logger message="|||| DONE" level="INFO" />
</flow>
NB. Alternatively, if using a collection-aggregator is an issue because it uses too much memory, you could use an expression component to decrement sessionVars.expectedMessageCount and filter to let a message hit the final message processor when the counter is back to 0.