2014-03-12 44 views
0

我有一個查詢Oracle數據庫的騾流,每隔一段時間Oracle數據庫就會脫機進行維護,但當它恢復時,Mule會在重啓Mule服務或重新部署流程之前,不要嘗試重新建立連接。騾子捕捉異常策略不會觸發Oracle JDBC IO錯誤

在騾子工作室,我看到有一個重新連接方案...所以我可以將其設置爲永遠重試這樣的... ...

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

但是,如果騾子是無法連接到甲骨文一個小時,我一定會收到電子郵件通知。

我想我會設置的重試次數到60倍,並嘗試每一分鐘,所以如果甲骨文仍下降連接將失敗讓騾子捕獲錯誤並給我發來電子郵件...

然而,當我測試了這個(下面的流程)之後,流程將在達到重試次數後失敗,但是捕獲異常策略不會被觸發。

<?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 [email protected]: 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

如果連接器斷開,其入站端點將停止。這就是爲什麼你嘗試做不到的原因。

您需要做的是將您的監視工具指向您的Mule實例的JMX樹,並監視JDBC連接器的狀態,如果它未連接並啓動超過一個小時,則會發出警報。另外,如果你想讓Mule自我監控(一般來說==不總是明智的),你可以創建一個定期使用Quartz入站端點或輪詢器觸發的流程,它將檢查JDBC連接器的狀態直接在註冊表中,通過電子郵件通知您遇到了麻煩。

0

嘗試在重新連接策略設置blocking="false"

+0

感謝您的建議,我試過這個,但我仍然得到相同的結果...異常策略沒有觸發。 –

+0

這不是例外,但成功的重新連接。 – Seba

0

嘗試添加一個custom default exception strategy到你的mule配置。由於這是連接器級別異常<catch-exception-strategy>的流量可能沒有幫助。

以下鏈接提供有關自定義默認例外策略的更多信息。

Mule Custom Default Exception Strategy

參考自定義默認異常策略部分

希望這有助於。

+0

謝謝,我添加默認異常策略時出現此錯誤... cvc-complex-type.2.4.a:發現無效內容從元素'default-exception-strategy'開始。 –

+0

根據所需數據更新答案。嘗試一下。 – user1760178

+0

謝謝,我遵循你發送的文檔,但我仍然無法得到觸發的異常......這就是我剛纔的流程... <配置defaultExceptionStrategy-ref =「Catch_Exception_Strategy」doc:name =「Configuration」/> –