Mule catch exception strategy doesn't trigger on Oracle JDBC IO Error

落花浮王杯 提交于 2019-12-25 06:18:10

问题


I've got a mule flow that queries an Oracle database, every once in awhile the Oracle database will get taken offline for maintenance but when it comes back up Mule will not try to re-establish a connection until I either restart the Mule service or re-deploy the flow.

In Mule Studio I saw there was a re-connection strategy... so I could just set it to retry forever like this...

<jdbc:connector name="JDBC" dataSource-ref="Oracle_Data_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="JDBC">
    <reconnect-forever frequency="60000"/>
</jdbc:connector>

However, if Mule isn't able to connect to Oracle for an hour I'd sure like to get an email notification.

I figured I'd set the retry count to 60 times and try every minute so if Oracle was still down the connection will fail so that Mule catches the error and sends me an email...

However, when I tested this (flow below) the flow will fail after the number of retries is reached but the catch exception strategy doesn't get triggered.

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp" xmlns:jdbc="http://www.mulesoft.org/schema/mule/jdbc" 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.4.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
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/jdbc http://www.mulesoft.org/schema/mule/jdbc/current/mule-jdbc.xsd
http://www.mulesoft.org/schema/mule/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<context:property-placeholder location="properties" />

<jdbc:oracle-data-source name="Oracle_Data_Source" user="${oracle.user}" password="${oracle.password}" url="${oracle.url}" transactionIsolation="UNSPECIFIED" doc:name="Oracle Data Source"/>
<jdbc:connector name="JDBC" dataSource-ref="Oracle_Data_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="6000" doc:name="JDBC" >
    <reconnect frequency="6000" count="5"/>
</jdbc:connector>
<flow name="oracle_to_formsFlow1" doc:name="oracle_to_formsFlow1" initialState="started">
    <jdbc:inbound-endpoint queryTimeout="-1" pollingFrequency="1000" connector-ref="JDBC" doc:name="Database" queryKey="test">
        <jdbc:query key="test" value="SELECT * FROM MULE_TRANSACTIONS"/>
    </jdbc:inbound-endpoint>
    <smtp:outbound-endpoint host="${smtp.server}" responseTimeout="10000" doc:name="SMTP" from="${smtp.from}" subject="Mule Test" to="${smtp.to}"/>
    <catch-exception-strategy doc:name="Catch Exception Strategy">
        <smtp:outbound-endpoint host="${smtp.server}" responseTimeout="10000" doc:name="SMTP" from="${smtp.from}" subject="Mule Error" to="${smtp.to}"/>
    </catch-exception-strategy>
</flow>

Here's what happens...

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Starting app 'oracle_to_forms'                           +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INFO  2014-03-12 10:00:07,980 [main] org.mule.util.queue.TransactionalQueueManager: Starting ResourceManager
INFO  2014-03-12 10:00:07,986 [main] org.mule.util.queue.TransactionalQueueManager: Started ResourceManager
INFO  2014-03-12 10:00:07,988 [main] org.mule.transport.email.SmtpConnector: Connected: SmtpConnector
{
  name=connector.smtp.mule.default
  lifecycle=initialise
  this=33d15244
  numberOfConcurrentTransactedReceivers=4
  createMultipleTransactedReceivers=true
  connected=true
  supportedProtocols=[smtp]
  serviceOverrides=<none>
}

INFO  2014-03-12 10:00:07,989 [main] org.mule.transport.email.SmtpConnector: Starting: SmtpConnector
{
  name=connector.smtp.mule.default
  lifecycle=initialise
  this=33d15244
  numberOfConcurrentTransactedReceivers=4
  createMultipleTransactedReceivers=true
  connected=true
  supportedProtocols=[smtp]
  serviceOverrides=<none>
}

INFO  2014-03-12 10:00:07,989 [main] org.mule.lifecycle.AbstractLifecycleManager: Starting connector: connector.smtp.mule.default
ERROR 2014-03-12 10:00:09,147 [main] org.mule.retry.notifiers.ConnectNotifier: Failed to connect/reconnect: JdbcConnector
{
  name=JDBC
  lifecycle=initialise
  this=2888efde
  numberOfConcurrentTransactedReceivers=4
  createMultipleTransactedReceivers=false
  connected=false
  supportedProtocols=[jdbc]
  serviceOverrides=<none>
}
. Root Exception was: Cannot get connection for URL jdbc:oracle:thin:@//oradb:1741/ORACLEDB : IO Error: The Network Adapter could not establish the connection(SQL Code: 0, SQL State: + null). Type: class java.sql.SQLException
INFO  2014-03-12 10:00:09,147 [main] org.mule.retry.policies.SimpleRetryPolicy: Waiting for 6000ms before reconnecting. Failed attempt 1 of 5
ERROR 2014-03-12 10:00:16,152 [main] org.mule.retry.notifiers.ConnectNotifier: Failed to connect/reconnect: JdbcConnector
{
  name=JDBC
  lifecycle=initialise
  this=2888efde
  numberOfConcurrentTransactedReceivers=4
  createMultipleTransactedReceivers=false
  connected=false
  supportedProtocols=[jdbc]
  serviceOverrides=<none>
}
. Root Exception was: Cannot get connection for URL jdbc:oracle:thin:@//oradb:1741/ORACLEDB : IO Error: The Network Adapter could not establish the connection(SQL Code: 0, SQL State: + null). Type: class java.sql.SQLException
INFO  2014-03-12 10:00:16,153 [main] org.mule.retry.policies.SimpleRetryPolicy: Waiting for 6000ms before reconnecting. Failed attempt 2 of 5
ERROR 2014-03-12 10:00:23,158 [main] org.mule.retry.notifiers.ConnectNotifier: Failed to connect/reconnect: JdbcConnector
{
  name=JDBC
  lifecycle=initialise
  this=2888efde
  numberOfConcurrentTransactedReceivers=4
  createMultipleTransactedReceivers=false
  connected=false
  supportedProtocols=[jdbc]
  serviceOverrides=<none>
}        . Root Exception was: Cannot get connection for URL jdbc:oracle:thin:@//oradb:1741/ORACLEDB : IO Error: The Network Adapter could not establish the connection(SQL Code: 0, SQL State: + null). Type: class java.sql.SQLException
INFO  2014-03-12 10:00:23,158 [main] org.mule.retry.policies.SimpleRetryPolicy: Waiting for 6000ms before reconnecting. Failed attempt 3 of 5
ERROR 2014-03-12 10:00:30,162 [main] org.mule.retry.notifiers.ConnectNotifier: Failed to connect/reconnect: JdbcConnector
{
  name=JDBC
  lifecycle=initialise
  this=2888efde
  numberOfConcurrentTransactedReceivers=4
  createMultipleTransactedReceivers=false
  connected=false
  supportedProtocols=[jdbc]
  serviceOverrides=<none>
}
. Root Exception was: Cannot get connection for URL jdbc:oracle:thin:@//oradb:1741/ORACLEDB : IO Error: The Network Adapter could not establish the connection(SQL Code: 0, SQL State: + null). Type: class java.sql.SQLException
INFO  2014-03-12 10:00:30,163 [main] org.mule.retry.policies.SimpleRetryPolicy: Waiting for 6000ms before reconnecting. Failed attempt 4 of 5
ERROR 2014-03-12 10:00:37,168 [main] org.mule.retry.notifiers.ConnectNotifier: Failed to connect/reconnect: JdbcConnector
{
  name=JDBC
  lifecycle=initialise
  this=2888efde
  numberOfConcurrentTransactedReceivers=4
  createMultipleTransactedReceivers=false
  connected=false
  supportedProtocols=[jdbc]
  serviceOverrides=<none>
}
. Root Exception was: Cannot get connection for URL jdbc:oracle:thin:@//oradb:1741/ORACLEDB : IO Error: The Network Adapter could not establish the connection(SQL Code: 0, SQL State: + null). Type: class java.sql.SQLException
INFO  2014-03-12 10:00:37,168 [main] org.mule.retry.policies.SimpleRetryPolicy: Waiting for 6000ms before reconnecting. Failed attempt 5 of 5
ERROR 2014-03-12 10:00:44,173 [main] org.mule.retry.notifiers.ConnectNotifier: Failed to connect/reconnect: JdbcConnector
{
  name=JDBC
  lifecycle=initialise
  this=2888efde
  numberOfConcurrentTransactedReceivers=4
  createMultipleTransactedReceivers=false
  connected=false
  supportedProtocols=[jdbc]
  serviceOverrides=<none>
}
. Root Exception was: Cannot get connection for URL jdbc:oracle:thin:@//oradb:1741/ORACLEDB : IO Error: The Network Adapter could not establish the connection(SQL Code: 0, SQL State: + null). Type: class java.sql.SQLException
ERROR 2014-03-12 10:00:44,178 [main] org.mule.module.launcher.application.DefaultMuleApplication: null
java.sql.SQLException: Cannot get connection for URL jdbc:oracle:thin:@//oradb:1741/ORACLEDB : IO Error: The Network Adapter could not establish the connection
    at org.enhydra.jdbc.standard.StandardDataSource.getConnection(StandardDataSource.java:216)
    at org.enhydra.jdbc.standard.StandardDataSource.getConnection(StandardDataSource.java:144)
    at org.mule.transport.jdbc.JdbcConnector.getConnection(JdbcConnector.java:254)
    at org.mule.transport.jdbc.JdbcConnector.doConnect(JdbcConnector.java:377)
    at org.mule.transport.AbstractConnector$5.doWork(AbstractConnector.java:1556)
    at org.mule.retry.policies.AbstractPolicyTemplate.execute(AbstractPolicyTemplate.java:67)
    at org.mule.transport.AbstractConnector.connect(AbstractConnector.java:1616)
    at org.mule.transport.AbstractConnector.start(AbstractConnector.java:428)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.mule.lifecycle.phases.DefaultLifecyclePhase.applyLifecycle(DefaultLifecyclePhase.java:225)
    at org.mule.lifecycle.RegistryLifecycleManager$RegistryLifecycleCallback.onTransition(RegistryLifecycleManager.java:276)
    at org.mule.lifecycle.RegistryLifecycleManager.invokePhase(RegistryLifecycleManager.java:155)
    at org.mule.lifecycle.RegistryLifecycleManager.fireLifecycle(RegistryLifecycleManager.java:126)
    at org.mule.registry.AbstractRegistryBroker.fireLifecycle(AbstractRegistryBroker.java:80)
    at org.mule.registry.MuleRegistryHelper.fireLifecycle(MuleRegistryHelper.java:120)
    at org.mule.lifecycle.MuleContextLifecycleManager$MuleContextLifecycleCallback.onTransition(MuleContextLifecycleManager.java:94)
    at org.mule.lifecycle.MuleContextLifecycleManager$MuleContextLifecycleCallback.onTransition(MuleContextLifecycleManager.java:90)
    at org.mule.lifecycle.MuleContextLifecycleManager.invokePhase(MuleContextLifecycleManager.java:72)
    at org.mule.lifecycle.MuleContextLifecycleManager.fireLifecycle(MuleContextLifecycleManager.java:64)
    at org.mule.DefaultMuleContext.start(DefaultMuleContext.java:255)
    at org.mule.module.launcher.application.DefaultMuleApplication.start(DefaultMuleApplication.java:147)
    at org.mule.module.launcher.application.ApplicationWrapper.start(ApplicationWrapper.java:107)
    at org.mule.module.launcher.DefaultMuleDeployer.deploy(DefaultMuleDeployer.java:48)
    at org.mule.tooling.server.application.ApplicationDeployer.run(ApplicationDeployer.java:58)
    at org.mule.tooling.server.application.ApplicationDeployer.main(ApplicationDeployer.java:91)
INFO  2014-03-12 10:00:44,180 [main] org.mule.module.launcher.application.DefaultMuleApplication: 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Disposing app 'oracle_to_forms'                          +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INFO  2014-03-12 10:00:44,180 [main] org.mule.lifecycle.AbstractLifecycleManager: Disposing RegistryBroker
 INFO  2014-03-12 10:00:44,191 [main] org.mule.config.spring.MuleApplicationContext: Closing org.mule.config.spring.MuleApplicationContext@6027b534: startup date [Wed Mar 12 10:00:05 PDT 2014]; root of context hierarchy
INFO  2014-03-12 10:00:44,193 [main] org.mule.construct.FlowConstructLifecycleManager: Disposing flow: oracle_to_formsFlow1
INFO  2014-03-12 10:00:44,194 [main] org.mule.processor.SedaStageLifecycleManager: Disposing service: oracle_to_formsFlow1.stage1
INFO  2014-03-12 10:00:44,195 [main] org.mule.lifecycle.AbstractLifecycleManager: Disposing connector: JDBC
INFO  2014-03-12 10:00:44,195 [main] org.mule.lifecycle.AbstractLifecycleManager: Disposing model: _muleSystemModel
INFO  2014-03-12 10:00:44,379 [main] org.mule.DefaultMuleContext: 
**********************************************************************
* Application "oracle_to_forms" shut down normally on: 3/12/14       *
* 10:00 AM                                                           *
* Up for: 0 days, 0 hours, 0 mins, 36.400 sec                        *
**********************************************************************
Exception in thread "main" org.mule.module.launcher.DeploymentStartException: SQLException: Cannot get connection for URL jdbc:oracle:thin:@//oradb:1741/ORACLEDB : IO Error: The Network Adapter could not establish the connection
    at org.mule.module.launcher.application.DefaultMuleApplication.start(DefaultMuleApplication.java:170)
    at org.mule.module.launcher.application.ApplicationWrapper.start(ApplicationWrapper.java:107)
    at org.mule.module.launcher.DefaultMuleDeployer.deploy(DefaultMuleDeployer.java:48)
    at org.mule.tooling.server.application.ApplicationDeployer.run(ApplicationDeployer.java:58)
    at org.mule.tooling.server.application.ApplicationDeployer.main(ApplicationDeployer.java:91)
Caused by: org.mule.retry.RetryPolicyExhaustedException: Cannot get connection for URL jdbc:oracle:thin:@//oradb:1741/ORACLEDB : IO Error: The Network Adapter could not establish the connection (java.sql.SQLException)
    at org.mule.retry.policies.AbstractPolicyTemplate.execute(AbstractPolicyTemplate.java:105)
    at org.mule.transport.AbstractConnector.connect(AbstractConnector.java:1616)
    at org.mule.transport.AbstractConnector.start(AbstractConnector.java:428)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.mule.lifecycle.phases.DefaultLifecyclePhase.applyLifecycle(DefaultLifecyclePhase.java:225)
    at org.mule.lifecycle.RegistryLifecycleManager$RegistryLifecycleCallback.onTransition(RegistryLifecycleManager.java:276)
    at org.mule.lifecycle.RegistryLifecycleManager.invokePhase(RegistryLifecycleManager.java:155)
    at org.mule.lifecycle.RegistryLifecycleManager.fireLifecycle(RegistryLifecycleManager.java:126)
    at org.mule.registry.AbstractRegistryBroker.fireLifecycle(AbstractRegistryBroker.java:80)
    at org.mule.registry.MuleRegistryHelper.fireLifecycle(MuleRegistryHelper.java:120)
    at org.mule.lifecycle.MuleContextLifecycleManager$MuleContextLifecycleCallback.onTransition(MuleContextLifecycleManager.java:94)
    at org.mule.lifecycle.MuleContextLifecycleManager$MuleContextLifecycleCallback.onTransition(MuleContextLifecycleManager.java:90)
    at org.mule.lifecycle.MuleContextLifecycleManager.invokePhase(MuleContextLifecycleManager.java:72)
    at org.mule.lifecycle.MuleContextLifecycleManager.fireLifecycle(MuleContextLifecycleManager.java:64)
    at org.mule.DefaultMuleContext.start(DefaultMuleContext.java:255)
    at org.mule.module.launcher.application.DefaultMuleApplication.start(DefaultMuleApplication.java:147)
    ... 4 more
Caused by: org.mule.transport.ConnectException: Cannot get connection for URL jdbc:oracle:thin:@//oradb:1741/ORACLEDB : IO Error: The Network Adapter could not establish the connection (java.sql.SQLException)
    at org.mule.transport.jdbc.JdbcConnector.getConnection(JdbcConnector.java:258)
    at org.mule.transport.jdbc.JdbcConnector.doConnect(JdbcConnector.java:377)
    at org.mule.transport.AbstractConnector$5.doWork(AbstractConnector.java:1556)
    at org.mule.retry.policies.AbstractPolicyTemplate.execute(AbstractPolicyTemplate.java:67)
    ... 22 more
Caused by: java.sql.SQLException: Cannot get connection for URL jdbc:oracle:thin:@//oradb:1741/ORACLEDB : IO Error: The Network Adapter could not establish the connection
    at org.enhydra.jdbc.standard.StandardDataSource.getConnection(StandardDataSource.java:216)
    at org.enhydra.jdbc.standard.StandardDataSource.getConnection(StandardDataSource.java:144)
    at org.mule.transport.jdbc.JdbcConnector.getConnection(JdbcConnector.java:254)
    ... 25 more

回答1:


If a connector is disconnected, its inbound endpoints are stopped. That's why what you try to do can not work.

What you need to do is to point your monitoring tool to your Mule instance's JMX tree and monitor the state of the JDBC connector, raising an alarm if it's not connected and started for more than an hour.

Alternatively, if you want Mule to self-monitor (generally speaking == not always wise), you can create a flow that fires regularly with a Quartz inbound endpoint or a poller and that will check the status of the JDBC connector directly in the registry, emailing you case of trouble.




回答2:


Try setting blocking="false" in the reconnection strategy.




回答3:


Try adding a custom default exception strategy to your mule config. As this is a connector level exception <catch-exception-strategy> of flow might not be helpful.

The following link provides more information on Custom Default Exception Strategy.

Mule Custom Default Exception Strategy

Refer to the Custom Default Exception Strategies section

Hope this helps.



来源:https://stackoverflow.com/questions/22359294/mule-catch-exception-strategy-doesnt-trigger-on-oracle-jdbc-io-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!