(十三) Nepxion-Thunder分布式RPC集成框架 - 事件发布
2016-03-19 20:51
375 查看
Nepxion-Thunder(QQ 群 471164539)发布在https://github.com/Nepxion/
基于Google Guava EventBus,实现事件驱动发布框架内部事件,解除耦合;发布外部事件,进行重试补偿,异常通知(邮件或短信通知)
1)eventbus - 基于Google Guava的进程内发布/订阅机制,支持同步和异步事件发布
2)mobile - 基于EventBus的异常信息的短信通知,未实现
3)protocol - 基于EventBus的异常信息的发布/拦截,是其它事件通知模块的基础
4)registry - 基于EventBus的上下线通知,通过Zookeeper的Watcher事件来发布
5)smtp - 基于EventBus的Smtp协议的邮件通知,支持普通邮件和SSL认证邮件
1. 系统通知
邮件通知,一旦框架中有异常抛出,立即通过给定的邮件予以通知,
短信通知,未实现
2. 业务层面的异常事件拦截
ProtocolEventInterceptor可以拦截和通知如下的异常:
- 业务系统中抛出的任何异常
- 业务系统定义的超时异常(异步和同步,但不支持广播)
- 框架的中间价宕机产生异常,目前只支持Netty
- 框架服务治理产生异常,例如限流异常
业务系统只需要继承ProtocolEventInterceptor,实现onEvent方法,就可以捕获全部异常抛出
public class ServiceEventInterceptor extends ProtocolEventInterceptor { @Override protected void onEvent(ProtocolEvent event) { ApplicationType applicationType = event.getApplicationType(); ActionType actionType = event.getActionType(); ProtocolType protocolType = event.getProtocolType(); ProtocolMessage protocolMessage = event.getProtocolMessage(); System.out.println("--------------------收到异步事件通知--------------------"); System.out.println("Application type=" + applicationType); System.out.println("Action type=" + actionType); System.out.println("Protocol type=" + protocolType); if (actionType != ActionType.SYSTEM) { System.out.println("Trace id=" + protocolMessage.getTraceId()); System.out.println("Interface=" + protocolMessage.getInterface()); System.out.println("Method=" + protocolMessage.getMethod()); System.out.println("Parameter types=" + Arrays.asList(protocolMessage.getParameterTypes())); System.out.println("Parameters=" + Arrays.asList(protocolMessage.getParameters())); } else { System.out.println("From url=" + protocolMessage.getFromUrl()); System.out.println("To url=" + protocolMessage.getToUrl()); } System.out.println("Exception=" + ExceptionUtil.toExceptionString(protocolMessage.getException())); System.out.println("-------------------------------------------------------"); } }
框架接入比较简单,见下面的示例
<?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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:thunder="http://www.nepxion.com/schema/thunder" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.nepxion.com/schema/thunder http://www.nepxion.com/schema/thunder/thunder-1.0.xsd"> ....... <!-- 异常的EventBus事件发布拦截 --> <bean id="eventInterceptor" class="com.nepxion.thunder.service.ServiceEventInterceptor"/> </beans>
相关文章推荐
- (十五) Nepxion-Thunder分布式RPC集成框架 - 序列化
- (十四) Nepxion-Thunder分布式RPC集成框架 - 调用链
- (十六) Nepxion-Thunder分布式RPC集成框架 - Spring Boot + Docker部署
- Android事件总线 ( AndroidEventBus ) 框架发布
- 《连载 | 物联网框架ServerSuperIO教程》- 18.集成OPC Client,及使用步骤。附:3.5 发布与更新说明。
- 利用resteasy框架构建rest webservice----第四波:resteasy与spring真正集成发布我们的restful webservice 服务(实例、教程)
- 《连载 | 物联网框架ServerSuperIO教程》- 17.集成Golden实时数据库,高并发保存测点数据。附:3.4 发布与版本更新说明。
- 《连载 | 物联网框架ServerSuperIO教程》- 18.集成OPC Client,及使用步骤。附:3.5 发布与更新说明。
- 工作流管理系统开发之十三 流程与电子表单集成之事件实现篇
- 《连载 | 物联网框架ServerSuperIO教程》- 16.集成OPC Server,及使用步骤。附:3.3 发布与版本更新说明。
- 【FastDev4Android框架开发】AndroidAnnnotations注入框架使用之第三方框架集成RoboGuice(十三)
- Maven项目集成cxf框架发布WebService
- [Spring] SpringBoot 集成 Reactor 事件处理框架
- PDF.NET数据开发框架之集成开发工具Ver 4.1发布
- 《连载 | 物联网框架ServerSuperIO教程》- 17.集成Golden实时数据库,高并发保存测点数据。附:3.4 发布与版本更新说明。
- Spring 集成CXF框架发布Webservice服务 和 使用jdk生成Webservice clinet
- 【FastDev4Android框架开发】AndroidAnnnotations注入框架使用之第三方框架集成Otto事件总线(十四)
- 利用resteasy框架构建rest webservice----第四波:resteasy与spring真正集成发布我们的restful webservice 服务(实例、教程)
- Spring 4 官方文档学习(十三)集成其他web框架
- Android事件总线 ( AndroidEventBus ) 框架发布