Dami 基于事件总线的本地过程调用框架(首次发版)

1,047次阅读
没有评论

多元共进|2023
Google 开发者大会 精彩演讲回顾
Dami 基于事件总线的本地过程调用框架(首次发版)

Dami,专为本地多模块之间通讯解耦而设计(尤其是未知模块、隔离模块、领域模块)。零依赖,特适合 DDD。

特点

结合 Bus 与 RPC 的概念,可作事件分发,可作接口调用,可作异步响应。

  • 支持事务传导(同步分发、异常透传)
  • 支持事件标识、拦截器(方便跟踪)
  • 支持监听者排序、附件传递(多监听时,可相互合作)
  • 支持 Bus 和 Api 两种体验风格

与常见的 EventBus、ApiBean 的区别

 
Dami
EventBus
ApiBean
Dami 的情况说明

广播



发送(send)+ 监听(listen)
以及 Api 模式

应答



请求并等响应(requestAndResponse)+ 响应(response)
以及 Api 模式

回调
有+

有-
请求并等回调(requestAndCallback)+ 响应(response)

耦合
弱-
弱+
强++
 

依赖配置

<dependency>
<groupId>org.noear</groupId>
<artifactId>dami</artifactId>
<version>0.20.2</version>
</dependency>

如果涉及类加载器隔离:请在主程序标为编译,在其它模块标为可选。

示例

demo21_send

public class Deom11 {
static String topic = “demo.hello”;

public static void main(String[] args) {
//监听事件
Dami.<String,String>bus().listen(topic, payload -> {
System.err.println(payload);
});

//发送事件
Dami.<String,String>bus().send(topic, “world”);
}
}

demo12_request

public class Demo12 {
static String topic = “demo.hello”;

public static void main(String[] args) {
//监听事件
Dami.busStr().listen(topic, payload -> {
System.err.println(payload);

if (payload.isRequest()) {
Dami.busStr().response(payload, “hi nihao!”); // requestAndResponse 只接收第一个
Dami.busStr().response(payload, “* hi nihao!”);
Dami.busStr().response(payload, “** hi nihao!”);
}
});

//发送事件
String rst1 = Dami.busStr().requestAndResponse(topic, “world”);
System.out.println(rst1);

Dami.busStr().requestAndCallback(topic, “world”, rst2 -> {
System.out.println(rst2); //callback 可不限返回
});
}
}

demo31_api

public interface UserEventSender {
void onCreated(Long userId, String name);
Long getUserId(String name);
}

public class UserEventListenerImpl {
public void onCreated(Long userId, String name) {
System.err.println(“onCreated: userId=” + userId + “, name=” + name);
}

public Long getUserId(String name) {
return Long.valueOf(name.hashCode());
}
}

public class Demo31 {
public static void main(String[] args) {
//注册监听器
UserEventListenerOfModule1 userEventListener = new UserEventListenerOfModule1();
Dami.api().registerListener(“demo.user”, userEventListener);

//生成发送器
UserEventSender userEventSender = Dami.api().createSender(“demo.user”, UserEventSender.class);

//发送测试
userEventSender.onCreated(1L, “noear”);
Long userId = userEventSender.getUserId( “dami”);
System.err.println(“收到:响应:userId:” + userId);

//注销监听器
Dami.api().unregisterListener(“demo.user”, userEventListener);
}
}

Read More 

正文完
可以使用微信扫码关注公众号(ID:xzluomor)
post-qrcode
 0
评论(没有评论)

文心AIGC

2023 年 9 月
 123
45678910
11121314151617
18192021222324
252627282930  
文心AIGC
文心AIGC
人工智能ChatGPT,AIGC指利用人工智能技术来生成内容,其中包括文字、语音、代码、图像、视频、机器人动作等等。被认为是继PGC、UGC之后的新型内容创作方式。AIGC作为元宇宙的新方向,近几年迭代速度呈现指数级爆发,谷歌、Meta、百度等平台型巨头持续布局
文章搜索
热门文章
潞晨尤洋:日常办公没必要上私有模型,这三类企业才需要 | MEET2026

潞晨尤洋:日常办公没必要上私有模型,这三类企业才需要 | MEET2026

潞晨尤洋:日常办公没必要上私有模型,这三类企业才需要 | MEET2026 Jay 2025-12-22 09...
面向「空天具身智能」,北航团队提出星座规划新基准丨NeurIPS’25

面向「空天具身智能」,北航团队提出星座规划新基准丨NeurIPS’25

面向「空天具身智能」,北航团队提出星座规划新基准丨NeurIPS’25 鹭羽 2025-12-13 22:37...
5天连更5次,可灵AI年末“狂飙式”升级

5天连更5次,可灵AI年末“狂飙式”升级

5天连更5次,可灵AI年末“狂飙式”升级 思邈 2025-12-10 14:28:37 来源:量子位 让更大规...
钉钉又发新版本!把 AI 搬进每一次对话和会议

钉钉又发新版本!把 AI 搬进每一次对话和会议

钉钉又发新版本!把 AI 搬进每一次对话和会议 梦晨 2025-12-11 15:33:51 来源:量子位 A...
商汤Seko2.0重磅发布,合作短剧登顶抖音AI短剧榜No.1

商汤Seko2.0重磅发布,合作短剧登顶抖音AI短剧榜No.1

商汤Seko2.0重磅发布,合作短剧登顶抖音AI短剧榜No.1 十三 2025-12-15 14:13:14 ...
最新评论
ufabet ufabet มีเกมให้เลือกเล่นมากมาย: เกมเดิมพันหลากหลาย ครบทุกค่ายดัง
tornado crypto mixer tornado crypto mixer Discover the power of privacy with TornadoCash! Learn how this decentralized mixer ensures your transactions remain confidential.
ดูบอลสด ดูบอลสด Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.
ดูบอลสด ดูบอลสด Pretty! This has been a really wonderful post. Many thanks for providing these details.
ดูบอลสด ดูบอลสด Pretty! This has been a really wonderful post. Many thanks for providing these details.
ดูบอลสด ดูบอลสด Hi there to all, for the reason that I am genuinely keen of reading this website’s post to be updated on a regular basis. It carries pleasant stuff.
Obrazy Sztuka Nowoczesna Obrazy Sztuka Nowoczesna Thank you for this wonderful contribution to the topic. Your ability to explain complex ideas simply is admirable.
ufabet ufabet Hi there to all, for the reason that I am genuinely keen of reading this website’s post to be updated on a regular basis. It carries pleasant stuff.
ufabet ufabet You’re so awesome! I don’t believe I have read a single thing like that before. So great to find someone with some original thoughts on this topic. Really.. thank you for starting this up. This website is something that is needed on the internet, someone with a little originality!
ufabet ufabet Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.
热评文章
读懂2025中国AI走向!公司×产品×人物×方案,最值得关注的都在这里了

读懂2025中国AI走向!公司×产品×人物×方案,最值得关注的都在这里了

读懂2025中国AI走向!公司×产品×人物×方案,最值得关注的都在这里了 衡宇 2025-12-10 12:3...
5天连更5次,可灵AI年末“狂飙式”升级

5天连更5次,可灵AI年末“狂飙式”升级

5天连更5次,可灵AI年末“狂飙式”升级 思邈 2025-12-10 14:28:37 来源:量子位 让更大规...
戴尔 x OpenCSG,推出⾯向智能初创企业的⼀体化 IT 基础架构解决方案

戴尔 x OpenCSG,推出⾯向智能初创企业的⼀体化 IT 基础架构解决方案

戴尔 x OpenCSG,推出⾯向智能初创企业的⼀体化 IT 基础架构解决方案 十三 2025-12-10 1...
九章云极独揽量子位三项大奖:以“一度算力”重构AI基础设施云格局

九章云极独揽量子位三项大奖:以“一度算力”重构AI基础设施云格局

九章云极独揽量子位三项大奖:以“一度算力”重构AI基础设施云格局 量子位的朋友们 2025-12-10 18:...
乐奇Rokid这一年,一路狂飙不回头

乐奇Rokid这一年,一路狂飙不回头

乐奇Rokid这一年,一路狂飙不回头 梦瑶 2025-12-10 20:41:15 来源:量子位 梦瑶 发自 ...