0
votes

I have use case as below.

In my mule flow I have Http as inbound endpoint and jdbc(SQL Server) as outbound. I am trying to insert a record to SQL server whenever flow gets invoked.I also have roll back exception strategy in global level with "on-redelivery-attempts-exceeded" block.

But when ever my database was down I am trying to insert , my flow going throwing exception. Roll back exception with redelivery count is not happing on the flow .

Please need your advice.

*flow file :*

<!-- <jdbc-ee:mssql-data-source name="MS_SQL_Data_Source" user="sa" password="mssql" url="jdbc:sqlserver://VIKRAM-PC\MSSQLEXPRESS:1433;databaseName=testsqldb" transactionIsolation="UNSPECIFIED" doc:name="MS SQL Data Source"/> -->


<jdbc-ee:connector name="Database" dataSource-ref="MSSQLDataSourceBean" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database"/>


<spring:beans>
    <spring:bean id="MSSQLDataSourceBean" name="MSSQLDataSourceBean" class="org.enhydra.jdbc.standard.StandardDataSource" >
        <spring:property name="driverName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
        <spring:property name="url" value="jdbc:sqlserver://VIKRAM-PC\MSSQLEXPRESS:1433;databaseName=testsqldb;user=sa;password=mssql;"/>
    </spring:bean>
</spring:beans>

<rollback-exception-strategy name="Rollback_Exception_Strategy" maxRedeliveryAttempts="3" when="#[exception.causedBy(java.lang.Exception)]"/>



<flow name="DataBaseAsOutBound" doc:name="DataBaseAsOutBound" processingStrategy="synchronous">
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8089" path="sqltest" doc:name="HTTP"/>
    <logger level="INFO" doc:name="Logger" message="$$$$$$$$$$$$$ start of the flow $$$$$$$$$$$$$$"/>


            <jdbc-ee:outbound-endpoint exchange-pattern="one-way" queryKey="insertque" queryTimeout="-1" connector-ref="Database" doc:name="Database">
                <jdbc-ee:query key="insertque" value="insert into tesdb(colone,coltwo) values(123,'vikkione')"/>
            </jdbc-ee:outbound-endpoint>            




</flow>

Note:removed schema locations

Regards Vikram

2

2 Answers

0
votes

Use the Until Successful processor if you want to retry the database insert:

http://blogs.mulesoft.org/meet-until-successful-store-and-forward-for-mule/

0
votes

You have to register the rollback-exception-strategy as default exception strategy:

<configuration defaultExceptionStrategy-ref="Rollback_Exception_Strategy" doc:name="Configuration">
    <http:config useTransportForUris="false"/>
</configuration>

Or add reference from certain flow:

<flow name="DataBaseAsOutBound" ...>
     <...>
     <exception-strategy ref="Rollback_Exception_Strategy" doc:name="Reference Exception Strategy"/>
</flow>

You might get another error Default exception strategy must not have expression attribute. It must accept any message. If so then remove when="#[exception.causedBy(java.lang.Exception)]" to make it a global exception strategy.