micro service

Outbox Pattern: 可靠的微服务数据交换模式

对于采用微服务架构的业务系统来说,很难做到只更新自身服务的数据,更多是要通知其它服务,哪些单据或档案由什么变成了什么。Outbox Pattern 使源服务 “read your own writes”,同时提供跨服务可靠,最终一致的数据交换。 微服务,最头疼的地方就是数据问题,如果你也曾经在业务系统中使用,一定深有体会。关于其它方案的探讨就不再深入了,感兴趣的可以看一下:Reliable Microservices Data Exchange With the Outbox Pattern 接下来只是照本宣科,应用到自己系统中。 注意:该模式与特定的实现选择并无关系,是否使用ORM,使用JPA/Hibernate,Spring Boot,等其它技术,其它语言。现在讨论一此细节 Outbox Table 的表结构: Column | Type | Modifiers --------------+------------------------+----------- id | uuid | not null aggregatetype | character varying(255) | not null aggregateid | character varying(255) | not null type | character varying(255) | not null payload | jsonb | not null id: 事件的唯一标识; 可以用于消费者判断是否重复消息. aggregatetype: 事件产生者的类型,比如生产订单. aggregateid: 事件产生者的ID