“通知和检查"的名称pubsub体系结构? [英] Name of "notification-and-check" pubsub architecture?

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

问题描述

基本pubsub体系结构问题.从较高的角度来看,在设计pubsub时,有时会在两种体系结构之间做出选择:

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

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

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

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页,他们将这两种变化描述为 push pull 模型.

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.

观察者模式的实现常常使主题广播有关该更改的其他信息.主题将此信息作为Update的参数传递.信息量可能相差很大.

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.

在一种极端情况下,我们称之为 push模型,该主题向观察者发送了有关更改的详细信息,无论他们是否愿意.另一个极端是拉模型;主题只会发送最少量的通知,什么也不会发送,观察者此后会明确要求细节.

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.

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

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.

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

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