mule esb exception(一)
来源:互联网 发布:免费远程监控软件 编辑:程序博客网 时间:2024/06/06 09:02
mule esb 异常分类
- system exception
- message exception
系统异常出现的两种情况:
- 应用启动时出的异常
- 连接外部系统时出现的异常
for example:读取文件,当文件正在写入时,file connector endpoint去读这个文件,出现的异常即为系统异常,stackoverflow也有相关参考
系统异常相当于java中的Error
由于系统异常处于应用不可用状态,重点分析 message exception
Message Exception
message exception适用如下情况:
信息源–>信息处理–>…n–>信息处理时如果处理的信息发生异常,就调用异常策略处理异常,异常中也可以有多个信息处理,然后到输出端(outbound message)
废话说了这么多,搞技术的重应用直接上例子
<?xml version="1.0" encoding="UTF-8"?><mule xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp" xmlns:file="http://www.mulesoft.org/schema/mule/file" 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="EE-3.6.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsdhttp://www.mulesoft.org/schema/mule/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.xsdhttp://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsdhttp://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd"> <!-- Typical Connector for Inbound Endpoint: Read files --> <file:connector name="input" autoDelete="true" pollingFrequency="1000" fileAge="600000" moveToDirectory="D:\mule\import\backup" moveToPattern="#[message.inboundProperties['originalFilename']].backup" doc:name="File" /> <!-- Typical Connector for Outbound Endpoint: Write files --> <file:connector name="output" doc:name="File" /> <catch-exception-strategy name="Catch_Exception_Strategy" > <logger message=" 文件名: #[message.inboundProperties['originalFilename']] 在 #[server.dateTime.format("yyyy.MM.dd HH:mm:ss '出现异常信息' ")] #[exception]" level="INFO" doc:name="Logger"/> <set-payload value="文件名: #[message.inboundProperties['originalFilename']] 在 #[server.dateTime.format("yyyy.MM.dd HH:mm:ss '出现异常信息' ")] #[exception]" doc:name="Set Payload"/> <smtp:outbound-endpoint host="smtp.mailserver.com" user="host" password="*****" to="test@163.com" from="fromtest@mailserver.com" subject="testfile" responseTimeout="10000" encoding="GB18030" mimeType="text/html" doc:name="SMTP"/> </catch-exception-strategy> <configuration defaultExceptionStrategy-ref="Catch_Exception_Strategy" doc:name="Configuration" doc:description="Use as implicit default exception strategy."/> <flow name="fileimport"> <file:inbound-endpoint connector-ref="input" path="D:\mule\import\input" doc:name="File" responseTimeout="10000"> <file:filename-wildcard-filter pattern="导出*.doc" /> </file:inbound-endpoint> <!-- <null-component /> --> <file:outbound-endpoint connector-ref="output" path="D:\mule\import\output" doc:name="File" responseTimeout="10000" /> </flow></mule>
以上例子测试ok,修改了发邮件部分,当然不能暴漏我的邮件服务器啦
<file:connector name="input" autoDelete="true" pollingFrequency="1000" fileAge="600000" moveToDirectory="D:\mule\import\backup" moveToPattern="#[message.inboundProperties['originalFilename']].backup" doc:name="File" /><file:connector name="output" doc:name="File" />
以上代码是 file connector inbound 参考这里
<catch-exception-strategy name="Catch_Exception_Strategy" > <logger message=" 文件名: #[message.inboundProperties['originalFilename']] 在 #[server.dateTime.format("yyyy.MM.dd HH:mm:ss '出现异常信息' ")] #[exception]" level="INFO" doc:name="Logger"/> <set-payload value="文件名: #[message.inboundProperties['originalFilename']] 在 #[server.dateTime.format("yyyy.MM.dd HH:mm:ss '出现异常信息' ")] #[exception]" doc:name="Set Payload"/> <smtp:outbound-endpoint host="smtp.mailserver.com" user="host" password="*****" to="test@163.com" from="fromtest@mailserver.com" subject="testfile" responseTimeout="10000" encoding="GB18030" mimeType="text/html" doc:name="SMTP"/> </catch-exception-strategy> <configuration defaultExceptionStrategy-ref="Catch_Exception_Strategy" doc:name="Configuration" doc:description="Use as implicit default exception strategy."/>
以上是对应的异常处理:
<logger message=" 文件名: #[message.inboundProperties['originalFilename']] 在 #[server.dateTime.format("yyyy.MM.dd HH:mm:ss '出现异常信息' ")] #[exception]" level="INFO" doc:name="Logger"/>
捕获异常后打印对应的日志信息
<set-payload value="文件名: #[message.inboundProperties['originalFilename']] 在 #[server.dateTime.format("yyyy.MM.dd HH:mm:ss '出现异常信息' ")] #[exception]" doc:name="Set Payload"/>
邮件内容信息在 payload中显示,所有赋值payload
<smtp:outbound-endpoint host="smtp.mailserver.com" user="host" password="*****" to="test@163.com" from="fromtest@mailserver.com" subject="testfile" responseTimeout="10000" encoding="GB18030" mimeType="text/html" doc:name="SMTP"/>
发邮件输出异常日志信息
<configuration defaultExceptionStrategy-ref="Catch_Exception_Strategy" doc:name="Configuration" doc:description="Use as implicit default exception strategy."/>
这段非常重要:上面定义的异常策略是为了后期引用,以上代码 指定默认的异常策略为 以上定义的异常:通过名称Catch_Exception_Strategy引用定义异常
以上是个完整的flow例子,一般情况下不会抛出异常,如果我想测试一下,抛出异常后是否会发邮件:
只能手工抛出异常:详细参考这里
添加如上代码
看这个类的实现:
/* *(c) 2003-2014 MuleSoft, Inc. This software is protected under international copyright *law. All use of this software is subject to MuleSoft's Master Subscription Agreement *(or other master license agreement) separately entered into in writing between you and *MuleSoft. If such an agreement is not in place, you may not use the software. */package org.mule.component.simple;import org.mule.api.MuleEventContext;import org.mule.api.lifecycle.Callable;/** * <code>NullComponent</code> is a service that is used as a placeholder. This * implementation will throw an exception if a message is received for it. */public class NullComponent implements Callable{ public Object onCall(MuleEventContext context) throws Exception { throw new UnsupportedOperationException("This service cannot receive messages. Service is: " + context.getFlowConstruct().getName()); }}
会抛出:UnsupportedOperationException异常
这样就会调用邮件处理输出端发送邮件:
打印异常信息如下:
先简单写到这里,后期再谈 mule esb exception
0 0
- mule esb exception(一)
- Mule-Esb学习笔记一
- Mule ESB 的基本概念(一)
- Mule ESB的component(一)——概念介绍
- MULE ESB 配置(三)
- MULE ESB 配置(三)
- Mule ESB
- mule esb
- Mule ESB
- Mule ESB 学习笔记(1)
- Mule ESB 学习笔记(2)
- Mule ESB 学习笔记(3)
- Mule ESB 学习笔记(1)
- Mule ESB 学习笔记(1)
- Mule ESB 学习笔记(2)
- Mule ESB 学习笔记(3)
- Mule ESB 学习笔记(4)
- Mule ESB 学习笔记(5)
- 控制android 编译源码生成odex .
- weblogic启动缓慢解决方案 . 启动到<Info> <Management> <BEA-141107>卡住不动
- swift开发ios笔记2--汤姆猫动画(帧动画)
- 今日总结20150603
- android常见异常总结
- mule esb exception(一)
- Volley cancel
- Linux下常用的C/C++开源Socket库
- leetcode 218: The Skyline Problem
- iOS中图片拉伸技巧
- Android网络通信的六种方式示例代码
- 关于mysql数据库在运行中出现MySQL server has gone away的问题解决
- 48.核心动画之基础动画
- pg_restore - 从一个由 pg_dump 创建的备份文件中恢复 PostgreSQL 数据库。