“通知和检查"的名称发布订阅架构? [英] Name of "notification-and-check" pubsub architecture?

本文介绍了“通知和检查"的名称发布订阅架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本的发布订阅架构问题.在高层次上,在设计 pubsub 时,我有时会面临两种架构之间的选择:

Basic pubsub architecture question. At a high level, when designing pubsub, I sometimes face a choice between two architectures:

  1. 发布突变或新状态".

某些数据库状态发生了变化,发布者通过 pubsub 通知该更改.但是它们在消息中包含了足够的信息,因此订阅者不需要在数据库上进行查找.想象一下,订阅者有一个数据库缓存.它可以接收突变或新状态,并在不进行查找的情况下更新其缓存.

Some DB state is mutated, and publishers notify of that change via pubsub. But they include enough information in the message so that the subscriber doesn't need to do a look-up on the DB. Imagine the subscriber has a cache of the DB. It could receive the mutations or new-state, and update its cache without doing a look-up.

  1. 通知和检查发布者仅通知有新的改变",这提示订阅者从数据库中提取最新的.这是更强大的 IMO.pubsub 可能无法保证交付顺序,并且此架构对此很健壮,而 #1 则不是,如果突变对顺序敏感.

我的问题是,这两种类型的架构有通用名称吗?谢谢!

My question is, is there a common name for these 2-types of architectures? Thanks!

推荐答案

发布/订阅在四人组设计模式一书中被称为观察者模式.在第 298 页,他们将这两种变体描述为 pushpull 模型.

Publish/Subscribe is known as the Observer Pattern in the Gang of Four Design Patterns book. On page 298 they describe these two variations as push and pull models.

观察者模式的实现通常让主题广播关于更改的附加信息.主题将此信息作为参数传递给更新.信息量可能会有很大差异.

Implementations of the Observer pattern often have the subject broadcast additional information about the change. The subject passes this information as an argument to Update. The amount of information may vary widely.

在一种极端情况下,我们称之为推送模型,主体向观察者发送有关更改的详细信息,无论他们是否愿意.另一个极端是拉动模型;主体只发送最少的通知,然后观察者明确询问细节.

At one extreme, which we call the push model, the subject sends observers detailed information about the change , whether they want it or not. At the other extreme is the pull model; the subject sends nothing but the most minimal notification, and observers ask for details explicitly thereafter.

拉模型强调主体对其观察者的无知,而推模型假设主体对观察者的需求有所了解.推送模型可能会降低观察者的可重用性,因为 Subject 类对 Observer 类做出的假设可能并不总是正确的.另一方面,拉模型可能效率低下,因为观察者类必须在没有主题帮助的情况下确定发生了什么变化.

The pull model emphasizes the subject's ignorance of its observers, whereas the push model assumes subjects know something about their observers' needs. The push model might make observers less reusable, because Subject classes make assumptions about Observer classes that might not always be true. On the other hand, the pull model may be inefficient, because Observer classes must ascertain what changed without help from the Subject.

这篇关于“通知和检查"的名称发布订阅架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆