随想 2018052202

本文深入探讨了事件驱动编程的核心概念,包括Observer设计模式和Pub-SubMQ设计模式的应用,介绍了如何通过Zookeeper的watch机制实现分布式环境下的业务解耦,并讨论了Spring框架中的事件处理机制及其配置方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

继续学习事件驱动编程:

 

1. 方法论中的: Observer 设计模式, Pub-Sub MQ设计模式

2. 业务之间的解耦,必须引入一个额外的一个组件来。还是那句话: add addtional indirecation layer for flexible or discompose.

3. Zookeeper 中 watch 机制也可以用来解耦(分布式),作为事件驱动执行器,FileWatch也是可以的

4. 事件、事件源、发布事件、消费事件、事件处理器 Executor

5. Spring: ApplicationContext, ApplicationEvent, ApplicationEventListner, @EventListener,  事件处理器的 并发处理需要配置 @Configuration

6. ApplicationEvent:  startup, refresh, shutdown 

7. @Async 可以使方法异步执行

 

publish<event> ----->  executor (ThreadPool)   <------- handler<event>

可获取结果的异步 PubSub 模式

1.  Publish event

2.  Tranlate event to internal bucket with id for exchange the information between producer & consumer

3.  Create Future<?> and save map container with bucket id

4.  Save internal bucket to local memory waiting for executor to send

5.  Way 1: directly create new FutureTask<?> with Callable<?> executing body and submit it to executor, after event is done by handler, Future<?> can be get 

6.  Way 2: Using ArrayBlockingQueue<?> with only 1 element inside subclass of Future<?>, and create a connetion between Future<?> and bucket id, after registering the 

     listener to executor for waiting for the event is done by handler. If done, set ArrayBlockingQueue<?> by finding object the subclass of Future<?> from container with bucket id

 

转载于:https://www.cnblogs.com/iiiDragon/p/9070573.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值