Apache Camel异常处理
来源:互联网 发布:linux登录密码修改 编辑:程序博客网 时间:2024/06/07 19:05
直接看代码
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不需要同时添加
7 0
- Apache Camel异常处理
- Apache Camel
- Apache Camel
- Apache Camel异常事务的实例和分析 -- 总述
- Apache Camel异常事务的实例和分析 -- 多线程事务
- Apache Camel 介绍
- apache camel removeEndpoints
- Apache Camel(1)
- apache Camel学习
- Apache Camel简介
- apache Camel 文档
- apache camel jetty http
- Apache Camel读取配置文件
- Apache Camel http4 blueprint
- 【Java.Apache.Camel】
- 什么时候使用Apache camel
- Apache Camel读取配置文件
- Apache Camel 基本概念理解
- Java操作Hbase增删改查(附带复合条件查询以及分页查询)
- Eclipse中设置在创建新类时自动生成注释
- UIAlertView使用全解
- Spring中不得不知道的知识
- ios开发使用Basic Auth 认证方式
- Apache Camel异常处理
- imagebutton的src和background有什么区别呢?
- JAVA基础学习--面向对象试题
- linux常用命令(32): /etc/group文件详解
- XHTML表单
- MySQL数据文件及常用工具
- 0912Android基础网络技术之Http协议访问网络
- 《Java编程思想》读书笔记2.一切都是对象
- sql 自定义排序