-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10008 from abpframework/eventboxes
Outbox & Inbox patterns for the distributed event bus
- Loading branch information
Showing
139 changed files
with
3,384 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> | ||
<ConfigureAwait ContinueOnCapturedContext="false" /> | ||
</Weavers> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> | ||
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. --> | ||
<xs:element name="Weavers"> | ||
<xs:complexType> | ||
<xs:all> | ||
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1"> | ||
<xs:complexType> | ||
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" /> | ||
</xs:complexType> | ||
</xs:element> | ||
</xs:all> | ||
<xs:attribute name="VerifyAssembly" type="xs:boolean"> | ||
<xs:annotation> | ||
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
<xs:attribute name="VerifyIgnoreCodes" type="xs:string"> | ||
<xs:annotation> | ||
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
<xs:attribute name="GenerateXsd" type="xs:boolean"> | ||
<xs:annotation> | ||
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
</xs:complexType> | ||
</xs:element> | ||
</xs:schema> |
25 changes: 25 additions & 0 deletions
25
framework/src/Volo.Abp.DistributedLocking/Volo.Abp.DistributedLocking.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Import Project="..\..\..\configureawait.props" /> | ||
<Import Project="..\..\..\common.props" /> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<AssemblyName>Volo.Abp.DistributedLocking</AssemblyName> | ||
<PackageId>Volo.Abp.DistributedLocking</PackageId> | ||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> | ||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> | ||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> | ||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> | ||
<RootNamespace /> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Volo.Abp.Core\Volo.Abp.Core.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="DistributedLock.Core" Version="1.0.2" /> | ||
</ItemGroup> | ||
|
||
</Project> |
9 changes: 9 additions & 0 deletions
9
...rc/Volo.Abp.DistributedLocking/Volo/Abp/DistributedLocking/AbpDistributedLockingModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Volo.Abp.Modularity; | ||
|
||
namespace Volo.Abp.DistributedLocking | ||
{ | ||
public class AbpDistributedLockingModule : AbpModule | ||
{ | ||
|
||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...rkCore.MySQL/Volo/Abp/EntityFrameworkCore/DistributedEvents/MySQLInboxConfigExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Volo.Abp.EventBus.Distributed; | ||
|
||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents | ||
{ | ||
public static class MySQLInboxConfigExtensions | ||
{ | ||
public static void UseMySQL<TDbContext>(this InboxConfig outboxConfig) | ||
where TDbContext : IHasEventInbox | ||
{ | ||
outboxConfig.ImplementationType = typeof(ISqlRawDbContextEventInbox<TDbContext>); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...kCore.MySQL/Volo/Abp/EntityFrameworkCore/DistributedEvents/MySQLOutboxConfigExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Volo.Abp.EventBus.Distributed; | ||
|
||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents | ||
{ | ||
public static class MySQLOutboxConfigExtensions | ||
{ | ||
public static void UseMySQL<TDbContext>(this OutboxConfig outboxConfig) | ||
where TDbContext : IHasEventOutbox | ||
{ | ||
outboxConfig.ImplementationType = typeof(ISqlRawDbContextEventOutbox<TDbContext>); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...racle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/IOracleDbContextEventInbox.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents | ||
{ | ||
public interface IOracleDbContextEventInbox<TDbContext> : IDbContextEventInbox<TDbContext> | ||
where TDbContext : IHasEventInbox | ||
{ | ||
|
||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...acle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/IOracleDbContextEventOutbox.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents | ||
{ | ||
public interface IOracleDbContextEventOutbox<TDbContext> : IDbContextEventOutbox<TDbContext> | ||
where TDbContext : IHasEventOutbox | ||
{ | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...Oracle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleDbContextEventInbox.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Options; | ||
using Volo.Abp.EventBus.Boxes; | ||
using Volo.Abp.EventBus.Distributed; | ||
using Volo.Abp.Timing; | ||
using Volo.Abp.Uow; | ||
|
||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents | ||
{ | ||
public class OracleDbContextEventInbox<TDbContext> : DbContextEventInbox<TDbContext> , IOracleDbContextEventInbox<TDbContext> | ||
where TDbContext : IHasEventInbox | ||
{ | ||
public OracleDbContextEventInbox( | ||
IDbContextProvider<TDbContext> dbContextProvider, | ||
IClock clock, | ||
IOptions<AbpEventBusBoxesOptions> eventBusBoxesOptions) | ||
: base(dbContextProvider, clock, eventBusBoxesOptions) | ||
{ | ||
} | ||
|
||
[UnitOfWork] | ||
public override async Task MarkAsProcessedAsync(Guid id) | ||
{ | ||
var dbContext = await DbContextProvider.GetDbContextAsync(); | ||
var tableName = dbContext.IncomingEvents.EntityType.GetSchemaQualifiedTableName(); | ||
|
||
var sql = $"UPDATE \"{tableName}\" SET \"Processed\" = '1', \"ProcessedTime\" = TO_DATE('{Clock.Now}', 'yyyy-mm-dd hh24:mi:ss') WHERE \"Id\" = HEXTORAW('{GuidToOracleType(id)}')"; | ||
await dbContext.Database.ExecuteSqlRawAsync(sql); | ||
} | ||
|
||
[UnitOfWork] | ||
public override async Task DeleteOldEventsAsync() | ||
{ | ||
var dbContext = await DbContextProvider.GetDbContextAsync(); | ||
var tableName = dbContext.IncomingEvents.EntityType.GetSchemaQualifiedTableName(); | ||
var timeToKeepEvents = Clock.Now - EventBusBoxesOptions.WaitTimeToDeleteProcessedInboxEvents; | ||
|
||
var sql = $"DELETE FROM \"{tableName}\" WHERE \"Processed\" = '1' AND \"CreationTime\" < TO_DATE('{timeToKeepEvents}', 'yyyy-mm-dd hh24:mi:ss')"; | ||
await dbContext.Database.ExecuteSqlRawAsync(sql); | ||
} | ||
|
||
protected virtual string GuidToOracleType(Guid id) | ||
{ | ||
return BitConverter.ToString(id.ToByteArray()).Replace("-", "").ToUpper(); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...racle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleDbContextEventOutbox.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore; | ||
using Volo.Abp.Uow; | ||
|
||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents | ||
{ | ||
public class OracleDbContextEventOutbox<TDbContext> : DbContextEventOutbox<TDbContext> , IOracleDbContextEventOutbox<TDbContext> | ||
where TDbContext : IHasEventOutbox | ||
{ | ||
public OracleDbContextEventOutbox(IDbContextProvider<TDbContext> dbContextProvider) | ||
: base(dbContextProvider) | ||
{ | ||
} | ||
|
||
[UnitOfWork] | ||
public override async Task DeleteAsync(Guid id) | ||
{ | ||
var dbContext = (IHasEventOutbox) await DbContextProvider.GetDbContextAsync(); | ||
var tableName = dbContext.OutgoingEvents.EntityType.GetSchemaQualifiedTableName(); | ||
|
||
var sql = $"DELETE FROM \"{tableName}\" WHERE \"Id\" = HEXTORAW('{GuidToOracleType(id)}')"; | ||
await dbContext.Database.ExecuteSqlRawAsync(sql); | ||
} | ||
|
||
protected virtual string GuidToOracleType(Guid id) | ||
{ | ||
return BitConverter.ToString(id.ToByteArray()).Replace("-", "").ToUpper(); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...acle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleInboxConfigExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Volo.Abp.EventBus.Distributed; | ||
|
||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents | ||
{ | ||
public static class OracleInboxConfigExtensions | ||
{ | ||
public static void UseOracle<TDbContext>(this InboxConfig outboxConfig) | ||
where TDbContext : IHasEventInbox | ||
{ | ||
outboxConfig.ImplementationType = typeof(IOracleDbContextEventInbox<TDbContext>); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...cle.Devart/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleOutboxConfigExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Volo.Abp.EventBus.Distributed; | ||
|
||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents | ||
{ | ||
public static class OracleOutboxConfigExtensions | ||
{ | ||
public static void UseOracle<TDbContext>(this OutboxConfig outboxConfig) | ||
where TDbContext : IHasEventOutbox | ||
{ | ||
outboxConfig.ImplementationType = typeof(IOracleDbContextEventOutbox<TDbContext>); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...kCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/IOracleDbContextEventInbox.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents | ||
{ | ||
public interface IOracleDbContextEventInbox<TDbContext> : IDbContextEventInbox<TDbContext> | ||
where TDbContext : IHasEventInbox | ||
{ | ||
|
||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...Core.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/IOracleDbContextEventOutbox.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents | ||
{ | ||
public interface IOracleDbContextEventOutbox<TDbContext> : IDbContextEventOutbox<TDbContext> | ||
where TDbContext : IHasEventOutbox | ||
{ | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...rkCore.Oracle/Volo/Abp/EntityFrameworkCore/DistributedEvents/OracleDbContextEventInbox.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Options; | ||
using Volo.Abp.EventBus.Boxes; | ||
using Volo.Abp.Timing; | ||
using Volo.Abp.Uow; | ||
|
||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents | ||
{ | ||
public class OracleDbContextEventInbox<TDbContext> : DbContextEventInbox<TDbContext> , IOracleDbContextEventInbox<TDbContext> | ||
where TDbContext : IHasEventInbox | ||
{ | ||
public OracleDbContextEventInbox( | ||
IDbContextProvider<TDbContext> dbContextProvider, | ||
IClock clock, | ||
IOptions<AbpEventBusBoxesOptions> eventBusBoxesOptions) | ||
: base(dbContextProvider, clock, eventBusBoxesOptions) | ||
{ | ||
} | ||
|
||
[UnitOfWork] | ||
public override async Task MarkAsProcessedAsync(Guid id) | ||
{ | ||
var dbContext = await DbContextProvider.GetDbContextAsync(); | ||
var tableName = dbContext.IncomingEvents.EntityType.GetSchemaQualifiedTableName(); | ||
|
||
var sql = $"UPDATE \"{tableName}\" SET \"Processed\" = '1', \"ProcessedTime\" = TO_DATE('{Clock.Now}', 'yyyy-mm-dd hh24:mi:ss') WHERE \"Id\" = HEXTORAW('{GuidToOracleType(id)}')"; | ||
await dbContext.Database.ExecuteSqlRawAsync(sql); | ||
} | ||
|
||
[UnitOfWork] | ||
public override async Task DeleteOldEventsAsync() | ||
{ | ||
var dbContext = await DbContextProvider.GetDbContextAsync(); | ||
var tableName = dbContext.IncomingEvents.EntityType.GetSchemaQualifiedTableName(); | ||
var timeToKeepEvents = Clock.Now - EventBusBoxesOptions.WaitTimeToDeleteProcessedInboxEvents; | ||
|
||
var sql = $"DELETE FROM \"{tableName}\" WHERE \"Processed\" = '1' AND \"CreationTime\" < TO_DATE('{timeToKeepEvents}', 'yyyy-mm-dd hh24:mi:ss')"; | ||
await dbContext.Database.ExecuteSqlRawAsync(sql); | ||
} | ||
|
||
protected virtual string GuidToOracleType(Guid id) | ||
{ | ||
return BitConverter.ToString(id.ToByteArray()).Replace("-", "").ToUpper(); | ||
} | ||
} | ||
} |
Oops, something went wrong.