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

1,134次阅读
没有评论

多元共进|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、百度等平台型巨头持续布局
文章搜索
热门文章
手把手教你用AI 10分钟生成一个APP!零基础也能搞定

手把手教你用AI 10分钟生成一个APP!零基础也能搞定

今日,我将向大家展示DeepSeek的全新玩法——从零开始,利用AI创建一个完整的应用程序。借助DeepSee...
最新评论
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.
热评文章
手把手教你用AI 10分钟生成一个APP!零基础也能搞定

手把手教你用AI 10分钟生成一个APP!零基础也能搞定

今日,我将向大家展示DeepSeek的全新玩法——从零开始,利用AI创建一个完整的应用程序。借助DeepSee...