Message Broker

本文介绍了一种基于RMI的事件代理机制,包括事件发布、订阅与取消订阅的过程。该机制通过远程接口实现消息发布与接收,利用任务线程池管理事件处理,确保高效的消息传递。

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

Event Broker based on RMI
1. EB Server(RMI Server) provides publish/subscribe/unSubscribe remote interfaces
   for publish interface, take one argument:EventMessage object. EventMessage encapsulates messageBody,messageType,etc.
  
   for subscribe interface, take two arguments:
   first is filter, using when publishing a message, we'll find the subscriber impacted
   second is SubscriberInterface, which is also a remote interface reside in client side. when subscribing an event,
   this interface provides a callback function. So when the event occurs(e.g. someone publishes the event),
   the callback method will be invoked on the client side just like a listener.

   for unSubscribe interface, only take one argument:SubscriberInterface. The EB Server
will maintain a subscription(subscription encapsulates SubscriberInterface and filter) list.
   this interface will remove the specific Subscriber(acctually it is the subscriberInterface, that is, a subscriber)


2. one of the EB Client(RMI client) locates the EB Server(RMI Server), construct your own
   filter & listener(SubscriberInterface) and subscribe events.
  
   for the implementation of subScribe behind the scene,
        first we'll create a new taskThread from ThreadPoolManager, and store the taskThread,
together with a taskQueue, to the hashtable in the ThreadPoolManager. Acctually, the taskThread
only processes the tasks associated with it, that is, every taskThread has its own taskQueue.
        then, construct a Subscription object and encapsulate filter,subscriber. The
Subscription object will kept in the EB server.
 

3. one of the EB Client(RMI client) locates the EB Server(RMI Server), then publish an EventMessage


4. EB server puts the EventMessage in a Event Pool

5. Acctually, except the creation of the ThreadPoolManager during initializing EB Server,
   a PublishThread also created. Once acquire an EventMessage from EventPool generated  in step 4,
   publish thread first filters the subscription list maintained in the EB Server, then
   enclose the intended subscription as a senderTask to the right taskThread. The senderTask
   has a interface such as run or execute which will be scheduled and invoked by taskThread.


6. for TheadPoolManager, also provides some other interfaces except creating taskThread for every subscriber.
   6.1 getNextTask: cause the taskThread will poll the taskQueue associated, after one task completes, taskThread
                will acquire the next task and execute
   6.2 addTask:pls refer to step 5, add senderTask to taskQueue associated with taskThread
   6.3 releaseTask: when unsubscribe or get error durring message informing, this method
       will be invoked and taskThread will stopped and related tasks will be released.


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值