0
votes

My flow consumes a message based on cron expression and I have deliberately added a groovy code to throw exception for testing JMS rollback. Rollback doesn't return the consumed message back in queue. Am I missing something here ?

Here is mule flow which is supposed to rollback the mule message after an exception is encountered.

<jms:activemq-connector name="jmsConnector" specification="1.1" brokerURL="tcp://localhost:61616" />
<jms:endpoint name="testqueue" queue="test.queue" connector-ref="jmsConnector" />

<flow name="quartzBasedDelivery">
    <quartz:inbound-endpoint jobName="deliveryJob" cronExpression="0 0/1 * * * ?">
        <quartz:endpoint-polling-job>
            <quartz:job-endpoint ref="testqueue" />
        </quartz:endpoint-polling-job>
    </quartz:inbound-endpoint>
    <logger message="QUARTZ found message for delivery #[payload]" level="INFO" />
    <scripting:component>
               <scripting:script engine="groovy">
                    throw new java.lang.RuntimeException();
                </scripting:script>
    </scripting:component>
    <file:outbound-endpoint path="/test/out" outputPattern="message-[function:dateStamp].txt" />
    <logger message="Message deliverd" level="INFO" />
</flow>

<flow name="copyFile">
    <file:inbound-endpoint  path="/test/in"/>
    <byte-array-to-string-transformer /> 
    <logger message="COPYFILE found message for test queue #[payload]" level="INFO" />
    <jms:outbound-endpoint queue="test.queue"/> 
</flow>

Here is the exception thrown by this flow -

    Exception stack is:
1. null (java.lang.RuntimeException)
  sun.reflect.NativeConstructorAccessorImpl:-2 (null)
2. java.lang.RuntimeException (javax.script.ScriptException)
  org.codehaus.groovy.jsr223.GroovyScriptEngineImpl:323 (http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/script/ScriptException.html)
3. Failed to invoke ScriptComponent{quartzBasedDelivery.component.559022270}. Component that caused exception is: ScriptComponent{quartzBasedDelivery.component.559022270}. Message payload is of type: String (org.mule.component.ComponentException)
  org.mule.component.AbstractComponent:148 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/component/ComponentException.html)
********************************************************************************
Root Exception stack trace:
java.lang.RuntimeException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
1
Where do you have transactions configured and a rollback exception strategy?Seba
@Seba the default exception strategy rolls back the transaction. So, even though I didn't mention roll back strategy ... it is implicit.user1493140

1 Answers

4
votes

In your case JMS Messages won't be redelivered to the originating queue by a Rollback Exception Strategy because you have a Quartz Inbound Endpoint, wich is not transactional or reliable. You can configure a Catch Exception Strategy and explicitly redeliver the message. Be careful with these scenarios because you can create an infinite loop.

Source: Rollback Exception Strategy

HTH