黄石网站建设维护,肥城网站制作,wordpress用户前端发文,中文软件开发工具DamiBus#xff0c;专为本地多模块之间通讯解耦而设计#xff08;尤其是未知模块、隔离模块、领域模块#xff09;。零依赖#xff0c;特适合 DDD。
特点
结合 Bus 与 RPC 的概念#xff0c;可作事件分发#xff0c;可作接口调用#xff0c;可作响应订阅。
支持事务传…DamiBus专为本地多模块之间通讯解耦而设计尤其是未知模块、隔离模块、领域模块。零依赖特适合 DDD。
特点
结合 Bus 与 RPC 的概念可作事件分发可作接口调用可作响应订阅。
支持事务传导同步分发、异常透传支持事件标识、拦截器方便跟踪支持监听者排序、附件传递多监听时可相互合作支持 Bus 和 Api 两种体验风格
与常见的 EventBus、ApiBean 的区别
DamiBusEventBusApiDamiBus 的情况说明广播有有无发送(send) 监听(listen)以及 Api 模式应答有无有发送并请求(sendAndRequest) 监听(listen) 答复(reply)以及 Api 模式回调有无有-发送并订阅(sendAndSubscribe) 监听(listen) 答复(reply)耦合弱-弱强
如果涉及类加载器隔离请在主程序标为编译在其它模块标为可选。
本次更新了什么
删除 Dami::intercept 接口直接使用 Dami.bus()::intercept更名 sendAndResponse 为 sendAndRequest!!!更名 sendAndCallback 为 sendAndSubscribe!!!添加 TopicDispatcher将调度处理与路由器开发更方便添加监控添加 InterceptorChain::getTargets 接口可以知道有哪些订阅添加 Acceptor::isSingle 接口用于识别单发还是多发接收添加 Payload::isSubscribe 接口用于识别订阅调整 启用新的配置方式配置路由时不需要重新实例化总线调整 接口默认方法处理策略有订阅执行订阅无订阅者执行默认调整 createSender 调整类加载器的主体调整 send,sendAndSubscribe 返回类型改为 bool马上可以知道是否有订阅目标
新增加的监视效果基于拦截器
public class Demo16_intercept {Testpublic void main() throws Exception {Dami.bus().intercept((payload, chain) - {System.out.println(开始监视...);if (chain.getTargets().size() 0) {System.out.println(没有订阅...);} else {chain.getTargets().forEach(e - System.out.println(e.getListener()));chain.doIntercept(payload);}System.out.println(结速监视...);});//发送事件Dami.bus().send(demo.hello, world);}
}另一个方案是用重载派发器的方法
public class Demo16_dispatcher {Testpublic void main() throws Exception {DamiConfig.configure(new TopicDispatcherMonitor());Dami.bus().send(demo.hello, world);}
}public class TopicDispatcherMonitorC,R extends TopicDispatcherDefaultC,R {Overrideprotected void doDispatch(PayloadC, R payload, ListTopicListenerHolderC, R targets) throws Throwable {//开始监视...System.out.println(开始监视...);//用 i可以避免遍历时添加监听的异常for (int i 0; i targets.size(); i) {TopicListenerPayloadC,R listener targets.get(i).getListener();//发送前监视...System.out.println(发送前监视...);listener.onEvent(payload);//发送后监视...System.out.println(发送后监视...);}//结速监视...System.out.println(结速监视...);}
}疑问 为什么不用分布式消息队列呢不好意思真的是不同的维度事儿。
项目地址
https://gitee.com/noear/damihttps://github.com/noear/dami