【发布时间】:2018-11-20 15:33:06
【问题描述】:
我有两个有界上下文,它们导致两个微服务
- 个人管理
- 文档存储
我在这里保持实体模型简单。
个人管理:
Entity/Table Person:
@id - int
tenantId - int
name - string
...
文档存储
Entity/Table Document:
@id - int
tenantId - int
personId - int
dateIssued - string
...
您需要知道,在启动应用程序之前 - 选择了一家公司(租户)来定义公司上下文。
我想使用 REST/JSON 存储一个新文档。
这是到 /tenants/1/persons/5/documents 的 POST
with the body
{
"dateIssued" : "2018-06-11"
}
在后端 - 我验证输入正文。
一个验证可能是“如果指定的人存在并且真的属于给定的租户”。
由于此信息存储在 PersonalManagement-MicroService 中,我需要提供如下操作:
"Does exists (personId=5,tenantId=1)"
在 PersonalManagement 中确保一致性,因为调用者可能是邪恶的。
一般来说:
在微服务中跨数据库检查实体“所有权”的最佳做法是什么
如果创建了一个新人 (tenantId,personId) 也可以选择将此信息另外存储(!)在 DocumentStorage 中,但希望避免这种冗余。
【问题讨论】:
标签: rest reference foreign-keys microservices