From 3ad093f696753da5f83c6b8f2dcbb0b076a8859f Mon Sep 17 00:00:00 2001 From: gdlcf88 Date: Thu, 8 Dec 2022 20:47:44 +0800 Subject: [PATCH] Update Distributed-Event-Bus.md --- docs/en/Distributed-Event-Bus.md | 50 ++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/docs/en/Distributed-Event-Bus.md b/docs/en/Distributed-Event-Bus.md index 21b1b07256..a3c1237cd7 100644 --- a/docs/en/Distributed-Event-Bus.md +++ b/docs/en/Distributed-Event-Bus.md @@ -499,6 +499,56 @@ Configure(options => }); ```` +## Entity Synchronizer + +Todo: introdution. + +### Create a Synchronizer Class + +Todo. + +```csharp +public class BlogUserSynchronizer : EntitySynchronizer, ITransientDependency +{ + public BlogUserSynchronizer(IObjectMapper objectMapper, IRepository repository) : + base(objectMapper, repository) + { + } +} +``` + +### Advanced Usages + +We may want to skip synchronizing the entity data on the external entity created, updated, or deleted. The `EntitySynchronizer` has three bool properties to control the handling behaviors. + +```csharp +public class BlogUserSynchronizer : EntitySynchronizer, ITransientDependency +{ + protected override bool IgnoreEntityCreatedEvent => true; + protected override bool IgnoreEntityUpdatedEvent => true; + protected override bool IgnoreEntityDeletedEvent => true; + + // ctor ... +} +``` + +### Eventual Consistency Guarantee + +Developers should always handle the distributed events disordering. ABP framework has an `EntityVersion` audit property to avoid an old version of entity data overriding a new one. + +The only thing we need to do is make the entity implement the `IHasEntityVersion` interface. + +```csharp +public class User : Entity, IHasEntityVersion +{ + public int EntityVersion { get; set; } +} +``` + +After that, the entity synchronizer will know the entity version number and skip handling the stale events. + +> See the community post [Notice and Solve ABP Distributed Events Disordering](https://community.abp.io/posts/notice-and-solve-abp-distributed-events-disordering-yi9vq3p4) for more if you are interested or worried. + ## See Also * [Local Event Bus](Local-Event-Bus.md)