我有一个查询Oracle数据库的mule流,每隔一段时间Oracle数据库就会脱机进行维护,但是当它恢复时,Mule将不会尝试重新建立连接,直到我重新启动Mule服务或重新部署流程。
在Mule Studio中,我看到有一个重新连接策略...所以我可以设置它像这样永远重试......
<jdbc:connector name="JDBC" dataSource-ref="Oracle_Data_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="JDBC">
<reconnect-forever frequency="60000"/>
</jdbc:connector>
但是,如果Mule无法连接到Oracle一小时,我肯定希望收到电子邮件通知。
我想我会将重试次数设置为60次并尝试每分钟,所以如果Oracle仍然关闭,连接将会失败,以便Mule捕获错误并向我发送电子邮件...
但是,当我测试这个(下面的流程)时,在达到重试次数后流程将失败但是捕获异常策略不会被触发。
<?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>
发生了什么......
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 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
参考文章已解决问题: