win08系统桥接_如何桥接状态系统和事件源系统

win08系统桥接

by Jonathan Solórzano-Hamilton

乔纳森·索洛萨诺·汉密尔顿(JonathanSolórzano-Hamilton)

如何桥接有状态和事件源系统(并击败大猩猩) (How to bridge stateful and event-sourced systems (and beat the gorilla))

You have a shiny new CQRS system, it’s “dev complete,” and you’re about to start integration testing. And the 800-pound gorilla that was sleeping in the corner during your domain discussions wakes up.

您有一个崭新的CQRS系统,它是“开发完成的”,并且您即将开始集成测试。 在您进行域讨论时,睡在角落里的800磅重的大猩猩醒了。

Without a single glance at your comprehensive domain diagrams, engaging user stories, UI mock-ups, or well-documented acceptance criteria, it bursts through the dotted-line “context boundary” that was supposed to hold it back.

无需一目了然的全面域图,引人入胜的用户故事,UI模拟或有据可查的验收标准,它就会突破本应阻止它的虚线“上下文边界”。

The gorilla rampages around the building shattering entities, reducing value to rubble, uprooting aggregates, and generally destroying all consensus on the project. Gorilla, thy name is Legacy Integration.

建筑物周围的大猩猩肆虐,破坏了瓦砾的价值,连根拔起了骨料,并普遍破坏了对该项目的所有共识。 大猩猩,您的名字叫Legacy Integration。

Legacy systems and process integration can sink an otherwise perfectly-executed project. It’s a monster migraine of a problem that only gets taught in the school of hard knocks. It’s also a problem that, as a developer, you will face in your career (if you haven’t already) when you start working with sufficiently established businesses and domains.

旧式系统和流程集成可能会使原本完美执行的项目陷入困境。 这是一个问题的怪异偏头痛,只有在硬敲门的学校才被教导。 这也是一个问题,作为开发人员,当您开始与足够成熟的企业和领域合作时,您将面对自己的职业生涯(如果还没有的话)。

Of course, if you’re lucky, you haven’t actually started coding yet — or at least it’s still early in the process-when the gorilla wakes up. Or, if you’re smart, you see the gorilla hiding under the lampshade in the corner and, rubbing the scars of your last encounter, you preempt its inevitable rampage by incorporating it into your architecture right from the start.

当然,如果幸运的话,您实际上还没有开始编码-或至少在大猩猩醒来的过程中还很早。 或者,如果您很聪明,您会看到大猩猩藏在角落的灯罩下,并且擦拭上次碰到的伤痕,从一开始就将其纳入建筑中,从而避免了不可避免的横冲直撞。

处理遗留系统 (Dealing with legacy systems)

As the Assistant Director of Architecture at the UCLA Office for Research Information Systems, I’m responsible for bridging a lot of system and data gaps. UCLA has a decades-long pipeline of legacy business processes and systems around research which butt up against any attempt to “disrupt” these traditional approaches with new technology.

作为UCLA研究信息系统办公室的架构助理总监,我负责弥合许多系统和数据差距。 加州大学洛杉矶分校(UCLA)围绕着研究已有数十年的传统业务流程和系统,这与任何试图用新技术“破坏”这些传统方法的尝试相抵触。

Most dauntingly, this pipeline is plugged with the occasional impenetrable iceberg of legacy data that often requires real-time wrangling.

最令人生畏的是,此管道中偶尔会出现难以穿透的遗留数据冰山,而这些冰山经常需要实时处理。

At my office, we’ve been tasked with providing integration into these legacy systems at an increasing pace. We’re also ramping up our bespoke transactional systems to handle small business processes.

在我的办公室,我们的任务是以越来越快的速度提供与这些旧系统的集成。 我们还将加强定制交易系统,以处理小型业务流程。

For our own systems, we’re generally following the microservice pattern. We’re incorporating more complexity, like domain-driven design (DDD) and event-sourcing, when needed. Our key challenge for these systems is legacy integration into state-persistence systems.

对于我们自己的系统,我们通常遵循微服务模式。 在需要时,我们将合并更多的复杂性,例如域驱动设计(DDD)和事件源。 这些系统的主要挑战是将遗留系统集成到状态持久性系统中。

接近整合 (Approaching integration)

I’m going to outline our approach in these next few paragraphs. It’s how we’ve tackled one of the problems that arises from bridging from an event-system, particularly a hybrid event system, to one that’s purely state-driven.

在接下来的几段中,我将概述我们的方法。 这就是我们解决了从事件系统(尤其是混合事件系统)桥接到纯粹由状态驱动的系统所引起的问题之一。

One key tenet that implementers often miss is that event sourcing should not be used everywhere. This is according to Greg Young, who is widely credited with introducing the “event sourcing” software architecture pattern.

实施者经常会错过的一个关键原则是, 不应任何地方使用事件源。 据格雷格·扬(Greg Young)说,他因引入“事件源”软件架构模式而广受赞誉。

In our systems, we use event sourcing to meet specifically targeted requirements. Sometimes this results in our applications having state that may reside outside of the event stream. Additionally, some of our event triggers come from unreliable source system state changes. This would demand a lot of post-hoc event correction and “rewind-replay” to fix if we were to depend only on the event stream.

在我们的系统中,我们使用事件源来满足特定的目标需求。 有时这会导致我们的应用程序具有可能驻留在事件流之外的状态。 此外,我们的某些事件触发器来自不可靠的源系统状态更改。 如果我们仅依赖事件流,那么这将需要大量事后事件纠正和“倒带重放”修复。

怀疑的解决方案 (A skeptical solution)

The solution we came up with for this is one I call the “Skeptical Subscriber.” The Skeptical Subscriber addresses the problem of “unreliability” in the event side of the system, at least from the perspective of the legacy state machine. It also addresses systems which may miss event generation due to external legacy data problems:

我们为此提出的解决方案是我称为“怀疑订阅者”的解决方案。 怀疑订户至少从传统状态机的角度解决了系统事件方面的“不可靠性”问题。 它还解决了由于外部遗留数据问题而可能错过事件生成的系统:

  1. The event source may generate events that do not result in state changes relevant to the legacy state machine. From its perspective, these are “false positive” events

    事件源可能会生成不会导致与旧版状态机有关的状态更改的事件。 从它的角度来看,这些都是“误报”事件
  2. The event source may fail to generate events for changes in state that are relevant to the legacy state machine. From its perspective, these are “missed” or “skipped” events

    事件源可能无法生成针对处于状态相关的传统状态机改变的事件。 从其角度来看,这些是“遗漏”或“跳过”事件

  3. Events may not be generated at all due to bugs or errors in the original source of the event. This particularly happens in extract-tranform-load (ETL) streams from legacy data repositories. From any perspective these are genuinely “skipped” events

    由于事件原始来源中的错误或错误,可能根本不会生成事件。 这尤其发生在来自旧数据存储库的提取-转换-加载(ETL)流中。 从任何角度看,这些都是真正的“跳过”事件

The Skeptical Subscriber approach addresses these concerns by remaining distrustful of the event stream. It treats the event stream as one possible trigger or notification that the state has changed, but it also accepts other possible triggers. It also distrusts that the notifications of state change are correct.

怀疑订阅者方法通过保持对事件流的不信任来解决这些问题。 它将事件流视为一种可能的触发器或状态已更改的通知,但它也接受其他可能的触发器。 它还不相信状态更改通知是正确的。

Once it’s notified that the state may have changed, the subscriber notifies a state gateway that queries the state of the event-sourced system.

收到状态可能已更改的通知后,订阅者会通知状态网关,该网关查询事件源系统的状态。

This state gateway evaluates the state against the last-known state (as the subscribing system knew it).

该状态网关根据最新已知状态(如订阅系统知道的那样)评估状态。

If the change is relevant, it then updates the subscribing system state and, if needed, initiates related subscribing system business processes.

如果更改是相关的,则它将更新订阅系统状态,并在需要时启动相关的订阅系统业务流程。

一些要求 (Some requirements)

In order to use this approach, your subscribing system needs to:

为了使用这种方法,您的订阅系统需要:

  1. Already persist, or be able to derive from what it does persist, the state attributes it cares about from the event sourcing system

    它已经从事件源系统中持久化了,或者能够从持久化的结果中得出它关心的状态属性
  2. Allow you to re-do how you inject state change data

    允许您重新执行注入状态更改数据的方式

Your event-sourcing system needs to:

您的事件源系统需要:

  1. Supply a query service that reliably represents the system state and includes all state attributes required by the subscribing system

    提供查询服务,该服务可靠地表示系统状态,并包括预订系统所需的所有状态属性
  2. Supply sufficient data in the event stream to locate the relevant records in the query service

    在事件流中提供足够的数据以在查询服务中找到相关记录
  3. Support a “list” or other batch query from the query service

    支持查询服务中的“列表”或其他批处理查询

The Skeptical Subscriber you implement must include:

您实现的怀疑订阅者必须包括:

  1. A State Gateway that can query the query service for a particular record (event driven) or for a list of records (other trigger, for catching up on “missed” events)

    可以查询查询服务的特定记录(事件驱动)或记录列表(其他触发器,用于追赶“丢失”事件的状态网关)的状态网关
  2. The State Gateway must include domain comparison logic from the context of the subscribing system that discards records if, as far as the subscribing domain is concerned, they have not changed

    如果就订阅域而言,状态网关尚未更改,则状态网关必须包括来自订阅系统上下文的域比较逻辑,该逻辑将丢弃记录
  3. An event subscription implementation to call the gateway per-record from the events

    一个事件订阅实现,用于从事件中按记录调用网关
  4. The ability to update the persistence layer of the subscribing system with the changes (so that it does not re-update the same record next time), such as through a repository

    具有通过更改来更新预订系统的持久层的能力(以便下次不重新更新同一记录),例如通过存储库

The Skeptical Subscriber may also implement the initiation of business processes in the subscribing system.

怀疑订阅可以在订阅系统中实现业务流程的启动。

If it’s purely state-driven, this may be through persisting new process records to launch the concomitant processes. Otherwise, it can call whatever process API is exposed.

如果它是纯粹由状态驱动的,则可能是通过保留新的流程记录来启动伴随的流程。 否则,它可以调用任何公开的流程API。

If you do initiate these business processes, you must also implement locking in the gateway so that you do not double-up on process initiation if an event trigger occurs during the ETL process.

如果您确实启动了这些业务流程,则还必须在网关中实施锁定,以便在ETL流程中发生事件触发时,也不会加倍进行流程启动。

积极成果 (Positive results)

There are plenty of other challenges associated with legacy systems integration, especially when moving between event-sourced and stateful contexts. This pattern, however, helps us minimize the technical burden associated with event maintenance when consuming legacy (and spotty) data.

与遗留系统集成相关的还有许多其他挑战,尤其是在事件源状态和有状态上下文之间移动时。 但是,这种模式有助于我们在使用旧版(和不可靠的)数据时最大程度地减少与事件维护相关的技术负担。

Prior to following this pattern, we’d been working in a strictly event-sourced approach. We had lost quick access to the support opportunities afforded by having a directly-editable state. With this pattern, we’ve regained those opportunities. When the legacy system is misbehaving because it doesn’t “like” the events that it’s getting, we have shifted the burden from modifying the event stream in some way to a simple state modification.

在遵循这种模式之前,我们一直在使用严格的基于事件的方法。 我们无法快速获得拥有直接可编辑状态所提供的支持机会。 通过这种模式,我们重新获得了这些机会。 当遗留系统由于不喜欢收到的事件而导致行为异常时,我们已经将负担从以某种方式修改事件流转移到了简单的状态修改上。

We’ve also added a layer of loose coupling to generally insulate the subscribing system from direct exposure to the events. This allows redirection of other subscribing system triggers.

我们还添加了一层松耦合,以使订阅系统免受直接暴露于事件的影响。 这允许重定向其他订阅系统触发器。

For example, a legacy ETL can serve as an initial state gateway trigger until you’re ready to switch to an event stream. And we’ve done so without over-complicating the CQRS service by implementing the interstitial skeptical subscriber as an independent entity.

例如,在准备好切换到事件流之前,旧式ETL可以用作初始状态网关触发器。 并且我们通过将插页式怀疑订阅者实现为独立实体,而没有使CQRS服务过度复杂化。

Here’s a pro tip for data scientists and the engineers who serve them: if you implement polyglot persistence in the subscribing repository, you can also build out a document store that is already automatically filtered to data changes that reflect a meaningful business process.

这是给数据科学家和为他们服务的工程师的专业提示:如果您在订阅存储库中实现多语言持久性,则还可以构建一个文档存储,该文档存储已经自动过滤为反映有意义的业务流程的数据更改。

Finally, in the event that an event is “skipped” or “missed,” we have an easy on-demand support pathway to follow. We either re-notify the subscriber about that record (if we’re aware of which record missed an event), or we perform a “catch-up” full-system query (if we’re not sure).

最后,如果事件被“跳过”或“遗漏”,我们将遵循简单的按需支持途径。 我们或者重新通知订户有关该记录的信息(如果我们知道哪个记录错过了事件),或者我们执行“追赶”的全系统查询(如果不确定)。

We can do this without having to touch the event stream. This means that other subscribing applications won’t be impacted by the support activity.

我们无需触摸事件流就可以做到这一点。 这意味着其他订阅应用程序不会受到支持活动的影响。

最后的想法 (Final thoughts)

It’s not the right fit for every problem (or even for most problems). But it’s a great solution for taking advantage of the loose coupling and other downstream benefits of event sourcing and CQRS, while minimizing support overhead for troubleshooting legacy data streams. This lets our developers spend more of their time writing new applications and increases our value to our consumers.

它不是适合每个问题(甚至大多数问题)的正确方法。 但这是利用事件源和CQRS的松散耦合和其他下游优势的绝佳解决方案,同时最大程度地减少了对旧数据流进行故障排除的支持开销。 这使我们的开发人员可以将更多的时间花在编写新应用程序上,并增加我们对消费者的价值。

If you enjoyed this post, please click the button below and give me some claps so more people see it. Thanks!

如果您喜欢这篇文章,请单击下面的按钮并给我一些鼓掌,以便更多的人看到它。 谢谢!

Jonathan is the Assistant Director of Architecture and Operations at UCLA’s department of Research Information Systems. After obtaining a Physics degree from Stanford University he went on to spend over 10 years working in information systems architecture, data-driven business process improvement, and organizational management. He is also the founder of Peach Pie Apps Workshop, a company that focuses on building data solutions for non-profits.

乔纳森(Jonathan)是加州大学洛杉矶分校研究信息系统部门的架构和运营助理总监。 从斯坦福大学获得物理学学位后,他继续在信息系统体系结构,数据驱动的业务流程改进和组织管理方面工作了10年以上。 他还是Peach Pie Apps Workshop的创始人,该公司专注于为非营利组织构建数据解决方案。

翻译自: https://www.freecodecamp.org/news/how-to-bridge-stateful-and-event-sourced-systems-70a419842e29/

win08系统桥接

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值