Event Collaboration 摘要

Resource

  • https://martinfowler.com/eaaDev/EventCollaboration.html

Digest

Interaction Model

Not limitted to WS type of thing, but things as simple as in-process objects interaction also follows these patterns. 

Request/Response Model
  • QUERY : One component needs information (STATE) that another has, so the needier component requests it
  • COMMAND : One component needs another to do something, out goes another request.
Event Model

Instead of components making requests when they need something, components (SOURCE) raise events when things change. Other components (LISTENER) then listen to events and react appropriately. 

Difference

  • One obvious difference is that the events are sent to everyone else, not just those components that are going to react.
  • The sender is just broadcasting the event, the sender does not need to know who is interested and who will respond.
  • The sender does not have to care about responses, allowing us to add behavior by plugging new components onto the event bus.
Command

At times the distinction is little more than phrasing, but at other times it does open the mind to different ways of doing things.

  • Command : tell the recipient to do something,
  • Event :  an event happened - inviting those interested to respond.
  • Simple Call v.s. Collaboration between different Listeners
Query
  • Query : Needier (Listener) query information from source. Request driven application speaks when spoke to.
    • Information/state managed in one place
  • Event : Source push information to Needier (Listener). Event driven application speaks when it has something to say.
    • Information/state managed in different places (source + listeners)
    • Information/state on listeners should be read-only

Pros/Cons

Pros
  • The great strength of Event Collaboration is that it affords a very loose coupling between its components.
  • A system that uses Event Collaboration is more resilient to breakdowns.
Cons
  • A component may continue operating, but it will be working on out of date information if it's not receiving events as things change.
  • Each individual component is simpler, the complexity of the interactions will increase.
  • This is made worse because these interactions are not clear by reading the source code. With Event Collaboration you don't know who is listening to the events until run-time - which in practice means you can only find the links between the components in configuration data - and there may be multiple areas of configuration data.

Message Endpoint

MessageEndpointSolution.gif

Message Endpoint code is custom to both the application and the messaging system’s client API.  It is the messaging endpoint code that takes that command or data, makes it into a message, and sends it on a particular messaging channel. It is the endpoint that receives a message, extracts the contents, and gives them to the application in a meaningful way.

The rest of the application knows little about message formats, messaging channels, or any of the other details of communicating with other applications via messaging. It just knows that it has a request or piece of data to send to another application, or is expecting those from another application.

转载于:https://my.oschina.net/u/3551123/blog/994936

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值