【发布时间】:2020-05-12 08:42:12
【问题描述】:
假设有两个微服务:A 和 B。每个都有自己的数据库。
A 有一个使用此方案的数据库:
{
"id": "unique id for the user",
"name": "the name of the user",
"email": "the email of the user",
"address": "the address of the user"
}
B 有这个方案:
{
"userId": "unique id for the user",
"email": "the email of the user"
}
每当我在 A 的数据库中插入一些内容时,都会调度一个事件,B 最终会得到它并保存从 A 的事件接收到的一些数据(当前是用户 ID 及其电子邮件)。 p>
一切都很好,B 的数据库有迄今为止注册的每个用户的用户 ID 和电子邮件。
现在,无论出于何种原因,我都需要 B 还拥有每个用户的地址,因此 B 的数据库架构将如下所示:
{
"userId": "unique id for the user",
"email": "the email of the user",
"address": "the address of the user"
}
现在,B 的数据库中的每个用户都可以有一个地址字段,但现在它们将为空。
我的问题是:有哪些方法可以使 B 的数据库与 A 的数据库保持一致(即如何更新 B 的每个用户以也填充地址)?
我知道我可以更新我的活动并现在包含地址,但它只适用于新用户,旧用户的地址为空。我应该扫描整个数据库并为每个用户手动分派一个事件吗?
【问题讨论】:
-
您的用例是什么?
标签: domain-driven-design microservices eventual-consistency