Apache Camel异常处理
2015-09-14 22:07
477 查看
直接看代码
根据上面的配置,很容易看出,bean2会抛异常
这样,在上面的那个route里面,只要有异常,就会路由到bean:errorBean里面去
注意,上面的route上的errorHandlerRef 和 camelContext上面的errorHandlerRef不需要同时添加
package com.lala.bean; import org.apache.camel.Exchange; import org.apache.camel.Processor; public class TestBean implements Processor { private String appId; public void process(Exchange exchange) throws Exception { if(appId == null || "".equals(appId)) { throw new NullPointerException("appId cannot be null ... "); } System.out.println(appId + " : --------------- " + this.getClass()); } public String getAppId() { return appId; } public void setAppId(String appId) { this.appId = appId; } }
package com.lala.bean; import org.apache.camel.Exchange; import org.apache.camel.Processor; public class Error implements Processor { public void process(Exchange exchange) throws Exception { System.out.println("-------------------------------------------"); //这样获取异常信息 Exception exce = exchange.getProperty("CamelExceptionCaught", Exception.class); System.out.println(exce.getMessage()); exce.printStackTrace(); } }
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <bean id="bean1" class="com.lala.bean.TestBean"> <property name="appId" value="wwwwwwww"></property> </bean> <bean id="bean2" class="com.lala.bean.TestBean"></bean> <bean id="bean3" class="com.lala.bean.TestBean"> <property name="appId" value="mmmmmmmm"></property> </bean> <bean id="errorBean" class="com.lala.bean.Error" /> <bean id="testErrorHandler" class="org.apache.camel.builder.DeadLetterChannelBuilder"> <property name="deadLetterUri" value="bean:errorBean"/> </bean> <camelContext errorHandlerRef="testErrorHandler" id="camelContext" xmlns="http://camel.apache.org/schema/spring"> <template id="camelContextTemplate" /> <route errorHandlerRef="testErrorHandler"> <from uri="direct:start-error" /> <to uri="bean:bean1" /> <to uri="bean:bean2" /> <to uri="bean:bean3" /> </route> </camelContext> </beans>
根据上面的配置,很容易看出,bean2会抛异常
这样,在上面的那个route里面,只要有异常,就会路由到bean:errorBean里面去
注意,上面的route上的errorHandlerRef 和 camelContext上面的errorHandlerRef不需要同时添加
相关文章推荐
- Web Services Tutorial with Apache CXF
- CXF
- Create CXF Client
- nutch2.3 hadoop2.6.0 hbase0.98.8 分布式爬虫NoClassDefFoundError: org/apache/hadoop/hbase/HBaseConfigurati
- 严重: Catalina.start: org.apache.catalina.LifecycleException: Failed to start component [StandardServ
- Apache Storm流处理有序性探究
- Apache工具集
- java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory的解决
- java.lang.NoClassDefFoundError: org/apache/log4j/Layout
- Apache Common DbUtils
- ield 'ClassID' doesn't have a default value 2015-09-14 13:37:25,015 ERROR [org.apache.struts2.dispatcher.Dispatcher] - Exception occurred during processing request: could not execute statement org.hibernate.exception.GenericJDBCException: could not execut
- ApacheServerStatus开启
- APACHE支持.htaccess以及 No input file specified解决方案
- apache本地多域配置(wampserver本地多域配置)
- apache Symbolic link not allowed or link target not accessible
- apache bench的简单使用
- centos6.4搭建apache+mysql+php环境
- 各种开源协议介绍 BSD、Apache Licence、GPL V2 、GPL V3 、LGPL、MIT
- [译]从LinkedIn,Apache Kafka到Unix哲学
- [译]从LinkedIn,Apache Kafka到Unix哲学