Mule catch异常策略不会在Oracle JDBC IO错误上触发 [英] Mule catch exception strategy doesn't trigger on Oracle JDBC IO Error

查看:90
本文介绍了Mule catch异常策略不会在Oracle JDBC IO错误上触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询Oracle数据库的m子流程,每隔一段时间Oracle数据库将脱机进行维护,但是当备份恢复时,Mule不会尝试重新建立连接,直到我重新启动ule子服务或重新部署流.

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.

在Mule Studio中,我看到了一种重新连接策略...因此我可以将其设置为像这样永久地重试...

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>

但是,如果Mule在一个小时内无法连接到Oracle,我肯定会收到一封电子邮件通知.

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

我认为我会将重试次数设置为60次并每分钟尝试一次,因此,如果Oracle仍处于关闭状态,则连接将失败,以便Mule捕获错误并向我发送电子邮件...

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...

但是,当我测试此(下面的流程)时,在达到重试次数之后该流程将失败,但是不会触发catch异常策略.

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

推荐答案

如果连接器断开连接,则其入站端点将停止.这就是为什么您尝试执行的操作行不通的原因.

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

您需要做的是将监视工具指向Mule实例的JMX树,并监视JDBC连接器的状态,如果未连接并启动了一个多小时,则会发出警报.

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.

或者,如果您希望Mule进行自我监控(通常说==并非总是明智的做法),则可以创建一个使用Quartz入站端点或轮询器定期触发的流,该流将直接检查JDBC连接器的状态在注册表中,通过电子邮件向您发送问题通知.

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.

这篇关于Mule catch异常策略不会在Oracle JDBC IO错误上触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆