mirror of https://github.com/abpframework/abp.git
committed by
GitHub
61 changed files with 1099 additions and 91 deletions
@ -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>); |
|||
} |
|||
} |
|||
} |
|||
@ -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>); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents |
|||
{ |
|||
public interface IOracleDbContextEventInbox<TDbContext> : IDbContextEventInbox<TDbContext> |
|||
where TDbContext : IHasEventInbox |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents |
|||
{ |
|||
public interface IOracleDbContextEventOutbox<TDbContext> : IDbContextEventOutbox<TDbContext> |
|||
where TDbContext : IHasEventOutbox |
|||
{ |
|||
} |
|||
} |
|||
@ -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(); |
|||
} |
|||
} |
|||
} |
|||
@ -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(); |
|||
} |
|||
} |
|||
} |
|||
@ -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>); |
|||
} |
|||
} |
|||
} |
|||
@ -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>); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents |
|||
{ |
|||
public interface IOracleDbContextEventInbox<TDbContext> : IDbContextEventInbox<TDbContext> |
|||
where TDbContext : IHasEventInbox |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents |
|||
{ |
|||
public interface IOracleDbContextEventOutbox<TDbContext> : IDbContextEventOutbox<TDbContext> |
|||
where TDbContext : IHasEventOutbox |
|||
{ |
|||
} |
|||
} |
|||
@ -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(); |
|||
} |
|||
} |
|||
} |
|||
@ -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(); |
|||
} |
|||
} |
|||
} |
|||
@ -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>); |
|||
} |
|||
} |
|||
} |
|||
@ -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>); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents |
|||
{ |
|||
public interface IPostgreSqlDbContextEventInbox<TDbContext> : IDbContextEventInbox<TDbContext> |
|||
where TDbContext : IHasEventInbox |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents |
|||
{ |
|||
public interface IPostgreSqlDbContextEventOutbox<TDbContext> : IDbContextEventOutbox<TDbContext> |
|||
where TDbContext : IHasEventOutbox |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,44 @@ |
|||
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 PostgreSqlDbContextEventInbox<TDbContext> : DbContextEventInbox<TDbContext>, IPostgreSqlDbContextEventInbox<TDbContext> |
|||
where TDbContext : IHasEventInbox |
|||
{ |
|||
public PostgreSqlDbContextEventInbox( |
|||
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\" = '{Clock.Now}' WHERE \"Id\" = '{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\" < '{timeToKeepEvents}'"; |
|||
await dbContext.Database.ExecuteSqlRawAsync(sql); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents |
|||
{ |
|||
public class PostgreSqlDbContextEventOutbox<TDbContext> : DbContextEventOutbox<TDbContext> , IPostgreSqlDbContextEventOutbox<TDbContext> |
|||
where TDbContext : IHasEventOutbox |
|||
{ |
|||
public PostgreSqlDbContextEventOutbox(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\" = '{id}'"; |
|||
await dbContext.Database.ExecuteSqlRawAsync(sql); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using Volo.Abp.EventBus.Distributed; |
|||
|
|||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents |
|||
{ |
|||
public static class PostgreSqlInboxConfigExtensions |
|||
{ |
|||
public static void UseNpgsql<TDbContext>(this InboxConfig outboxConfig) |
|||
where TDbContext : IHasEventInbox |
|||
{ |
|||
outboxConfig.ImplementationType = typeof(IPostgreSqlDbContextEventInbox<TDbContext>); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using Volo.Abp.EventBus.Distributed; |
|||
|
|||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents |
|||
{ |
|||
public static class PostgreSqlOutboxConfigExtensions |
|||
{ |
|||
public static void UseNpgsql<TDbContext>(this OutboxConfig outboxConfig) |
|||
where TDbContext : IHasEventOutbox |
|||
{ |
|||
outboxConfig.ImplementationType = typeof(IPostgreSqlDbContextEventOutbox<TDbContext>); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using Volo.Abp.EventBus.Distributed; |
|||
|
|||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents |
|||
{ |
|||
public static class SqlServerInboxConfigExtensions |
|||
{ |
|||
public static void UseSqlServer<TDbContext>(this InboxConfig outboxConfig) |
|||
where TDbContext : IHasEventInbox |
|||
{ |
|||
outboxConfig.ImplementationType = typeof(ISqlRawDbContextEventInbox<TDbContext>); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using Volo.Abp.EventBus.Distributed; |
|||
|
|||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents |
|||
{ |
|||
public static class SqlServerOutboxConfigExtensions |
|||
{ |
|||
public static void UseSqlServer<TDbContext>(this OutboxConfig outboxConfig) |
|||
where TDbContext : IHasEventOutbox |
|||
{ |
|||
outboxConfig.ImplementationType = typeof(ISqlRawDbContextEventOutbox<TDbContext>); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using Volo.Abp.EventBus.Distributed; |
|||
|
|||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents |
|||
{ |
|||
public static class SqliteInboxConfigExtensions |
|||
{ |
|||
public static void UseSqlite<TDbContext>(this InboxConfig outboxConfig) |
|||
where TDbContext : IHasEventInbox |
|||
{ |
|||
outboxConfig.ImplementationType = typeof(ISqlRawDbContextEventInbox<TDbContext>); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using Volo.Abp.EventBus.Distributed; |
|||
|
|||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents |
|||
{ |
|||
public static class SqliteOutboxConfigExtensions |
|||
{ |
|||
public static void UseSqlite<TDbContext>(this OutboxConfig outboxConfig) |
|||
where TDbContext : IHasEventOutbox |
|||
{ |
|||
outboxConfig.ImplementationType = typeof(ISqlRawDbContextEventOutbox<TDbContext>); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents |
|||
{ |
|||
public interface ISqlRawDbContextEventInbox<TDbContext> : IDbContextEventInbox<TDbContext> |
|||
where TDbContext : IHasEventInbox |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents |
|||
{ |
|||
public interface ISqlRawDbContextEventOutbox<TDbContext> : IDbContextEventOutbox<TDbContext> |
|||
where TDbContext : IHasEventOutbox |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
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 SqlRawDbContextEventInbox<TDbContext> : DbContextEventInbox<TDbContext> , ISqlRawDbContextEventInbox<TDbContext> |
|||
where TDbContext : IHasEventInbox |
|||
{ |
|||
public SqlRawDbContextEventInbox( |
|||
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 = '{Clock.Now}' WHERE Id = '{id.ToString().ToUpper()}'"; |
|||
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 < '{timeToKeepEvents}'"; |
|||
await dbContext.Database.ExecuteSqlRawAsync(sql); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents |
|||
{ |
|||
public class SqlRawDbContextEventOutbox<TDbContext> : DbContextEventOutbox<TDbContext> , ISqlRawDbContextEventOutbox<TDbContext> |
|||
where TDbContext : IHasEventOutbox |
|||
{ |
|||
public SqlRawDbContextEventOutbox(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 = '{id.ToString().ToUpper()}'"; |
|||
await dbContext.Database.ExecuteSqlRawAsync(sql); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.EventBus.Boxes |
|||
{ |
|||
public class AbpEventBusBoxesOptions |
|||
{ |
|||
/// <summary>
|
|||
/// Default: 6 hours
|
|||
/// </summary>
|
|||
public TimeSpan CleanOldEventTimeIntervalSpan { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Default: 1000
|
|||
/// </summary>
|
|||
public int InboxWaitingEventMaxCount { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Default: 1000
|
|||
/// </summary>
|
|||
public int OutboxWaitingEventMaxCount { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Period time of <see cref="InboxProcessor"/> and <see cref="OutboxSender"/>
|
|||
/// Default: 2 seconds
|
|||
/// </summary>
|
|||
public TimeSpan PeriodTimeSpan { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Default: 15 seconds
|
|||
/// </summary>
|
|||
public TimeSpan DistributedLockWaitDuration { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Default: 2 hours
|
|||
/// </summary>
|
|||
public TimeSpan WaitTimeToDeleteProcessedInboxEvents { get; set; } |
|||
|
|||
public AbpEventBusBoxesOptions() |
|||
{ |
|||
CleanOldEventTimeIntervalSpan = TimeSpan.FromHours(6); |
|||
InboxWaitingEventMaxCount = 1000; |
|||
OutboxWaitingEventMaxCount = 1000; |
|||
PeriodTimeSpan = TimeSpan.FromSeconds(2); |
|||
DistributedLockWaitDuration = TimeSpan.FromSeconds(15); |
|||
WaitTimeToDeleteProcessedInboxEvents = TimeSpan.FromHours(2); |
|||
} |
|||
} |
|||
} |
|||
@ -1,27 +1,72 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using MongoDB.Driver; |
|||
using MongoDB.Driver.Linq; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace Volo.Abp.MongoDB.DistributedEvents |
|||
{ |
|||
public class MongoDbContextEventOutbox<TMongoDbContext> : IMongoDbContextEventOutbox<TMongoDbContext> |
|||
public class MongoDbContextEventOutbox<TMongoDbContext> : IMongoDbContextEventOutbox<TMongoDbContext> |
|||
where TMongoDbContext : IHasEventOutbox |
|||
{ |
|||
public Task EnqueueAsync(OutgoingEventInfo outgoingEvent) |
|||
protected IMongoDbContextProvider<TMongoDbContext> MongoDbContextProvider { get; } |
|||
|
|||
public MongoDbContextEventOutbox(IMongoDbContextProvider<TMongoDbContext> mongoDbContextProvider) |
|||
{ |
|||
MongoDbContextProvider = mongoDbContextProvider; |
|||
} |
|||
|
|||
[UnitOfWork] |
|||
public virtual async Task EnqueueAsync(OutgoingEventInfo outgoingEvent) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
var dbContext = (IHasEventOutbox) await MongoDbContextProvider.GetDbContextAsync(); |
|||
if (dbContext.SessionHandle != null) |
|||
{ |
|||
await dbContext.OutgoingEvents.InsertOneAsync( |
|||
dbContext.SessionHandle, |
|||
new OutgoingEventRecord(outgoingEvent) |
|||
); |
|||
} |
|||
else |
|||
{ |
|||
await dbContext.OutgoingEvents.InsertOneAsync( |
|||
new OutgoingEventRecord(outgoingEvent) |
|||
); |
|||
} |
|||
} |
|||
|
|||
public Task<List<OutgoingEventInfo>> GetWaitingEventsAsync(int maxCount) |
|||
[UnitOfWork] |
|||
public virtual async Task<List<OutgoingEventInfo>> GetWaitingEventsAsync(int maxCount, CancellationToken cancellationToken = default) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
var dbContext = (IHasEventOutbox) await MongoDbContextProvider.GetDbContextAsync(cancellationToken); |
|||
|
|||
var outgoingEventRecords = await dbContext |
|||
.OutgoingEvents.AsQueryable() |
|||
.OrderBy(x => x.CreationTime) |
|||
.Take(maxCount) |
|||
.ToListAsync(cancellationToken: cancellationToken); |
|||
|
|||
return outgoingEventRecords |
|||
.Select(x => x.ToOutgoingEventInfo()) |
|||
.ToList(); |
|||
} |
|||
|
|||
public Task DeleteAsync(Guid id) |
|||
[UnitOfWork] |
|||
public virtual async Task DeleteAsync(Guid id) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
var dbContext = (IHasEventOutbox) await MongoDbContextProvider.GetDbContextAsync(); |
|||
if (dbContext.SessionHandle != null) |
|||
{ |
|||
await dbContext.OutgoingEvents.DeleteOneAsync(dbContext.SessionHandle, x => x.Id.Equals(id)); |
|||
} |
|||
else |
|||
{ |
|||
await dbContext.OutgoingEvents.DeleteOneAsync(x => x.Id.Equals(id)); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,38 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
using Volo.Abp.EventBus.Kafka; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.MongoDB; |
|||
using Volo.Abp.MongoDB.DistributedEvents; |
|||
|
|||
namespace DistDemoApp |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpMongoDbModule), |
|||
typeof(AbpEventBusKafkaModule), |
|||
typeof(DistDemoAppSharedModule) |
|||
)] |
|||
public class DistDemoAppMongoDbKafkaModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
context.Services.AddMongoDbContext<TodoMongoDbContext>(options => |
|||
{ |
|||
options.AddDefaultRepositories(); |
|||
}); |
|||
|
|||
Configure<AbpDistributedEventBusOptions>(options => |
|||
{ |
|||
options.Outboxes.Configure(config => |
|||
{ |
|||
config.UseMongoDbContext<TodoMongoDbContext>(); |
|||
}); |
|||
|
|||
options.Inboxes.Configure(config => |
|||
{ |
|||
config.UseMongoDbContext<TodoMongoDbContext>(); |
|||
}); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -1,12 +1,57 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Hosting; |
|||
using Serilog; |
|||
using Serilog.Events; |
|||
|
|||
namespace DistDemoApp |
|||
{ |
|||
class Program |
|||
public class Program |
|||
{ |
|||
static void Main(string[] args) |
|||
public static async Task<int> Main(string[] args) |
|||
{ |
|||
Console.WriteLine("Hello World!"); |
|||
Log.Logger = new LoggerConfiguration() |
|||
#if DEBUG
|
|||
.MinimumLevel.Debug() |
|||
#else
|
|||
.MinimumLevel.Information() |
|||
#endif
|
|||
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning) |
|||
.Enrich.FromLogContext() |
|||
.WriteTo.Async(c => c.File("Logs/logs.txt")) |
|||
.WriteTo.Async(c => c.Console()) |
|||
.CreateLogger(); |
|||
|
|||
try |
|||
{ |
|||
Log.Information("Starting console host."); |
|||
await CreateHostBuilder(args).RunConsoleAsync(); |
|||
return 0; |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Log.Fatal(ex, "Host terminated unexpectedly!"); |
|||
return 1; |
|||
} |
|||
finally |
|||
{ |
|||
Log.CloseAndFlush(); |
|||
} |
|||
|
|||
} |
|||
|
|||
internal static IHostBuilder CreateHostBuilder(string[] args) => |
|||
Host.CreateDefaultBuilder(args) |
|||
.UseAutofac() |
|||
.UseSerilog() |
|||
.ConfigureAppConfiguration((context, config) => |
|||
{ |
|||
//setup your additional configuration sources
|
|||
}) |
|||
.ConfigureServices((hostContext, services) => |
|||
{ |
|||
services.AddApplication<DistDemoAppMongoDbKafkaModule>(); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,26 @@ |
|||
using MongoDB.Driver; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.MongoDB; |
|||
using Volo.Abp.MongoDB.DistributedEvents; |
|||
|
|||
namespace DistDemoApp |
|||
{ |
|||
[ConnectionStringName("Default")] |
|||
public class TodoMongoDbContext : AbpMongoDbContext, IHasEventOutbox, IHasEventInbox |
|||
{ |
|||
public IMongoCollection<TodoItem> TodoItems => Collection<TodoItem>(); |
|||
public IMongoCollection<TodoSummary> TodoSummaries => Collection<TodoSummary>(); |
|||
|
|||
public IMongoCollection<OutgoingEventRecord> OutgoingEvents |
|||
{ |
|||
get => Collection<OutgoingEventRecord>(); |
|||
set {} |
|||
} |
|||
public IMongoCollection<IncomingEventRecord> IncomingEvents |
|||
{ |
|||
get => Collection<IncomingEventRecord>(); |
|||
set {} |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
{ |
|||
"ConnectionStrings": { |
|||
"Default": "mongodb://localhost:27018,localhost:27019,localhost:27020/DistEventsDemo" |
|||
}, |
|||
"Kafka": { |
|||
"Connections": { |
|||
"Default": { |
|||
"BootstrapServers": "localhost:9092" |
|||
} |
|||
}, |
|||
"EventBus": { |
|||
"GroupId": "DistDemoApp", |
|||
"TopicName": "DistDemoTopic" |
|||
} |
|||
}, |
|||
"Redis": { |
|||
"Configuration": "127.0.0.1" |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<OutputType>Exe</OutputType> |
|||
<TargetFramework>net5.0</TargetFramework> |
|||
<RootNamespace>DistDemoApp</RootNamespace> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\..\framework\src\Volo.Abp.MongoDB\Volo.Abp.MongoDB.csproj" /> |
|||
<ProjectReference Include="..\..\..\framework\src\Volo.Abp.EventBus.Rebus\Volo.Abp.EventBus.Rebus.csproj" /> |
|||
<ProjectReference Include="..\DistDemoApp.Shared\DistDemoApp.Shared.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<None Update="appsettings.json"> |
|||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
|||
</None> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,53 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Rebus.Persistence.InMem; |
|||
using Rebus.Transport.InMem; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
using Volo.Abp.EventBus.Rebus; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.MongoDB; |
|||
using Volo.Abp.MongoDB.DistributedEvents; |
|||
|
|||
namespace DistDemoApp |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpMongoDbModule), |
|||
typeof(AbpEventBusRebusModule), |
|||
typeof(DistDemoAppSharedModule) |
|||
)] |
|||
public class DistDemoAppMongoDbRebusModule : AbpModule |
|||
{ |
|||
public override void PreConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
PreConfigure<AbpRebusEventBusOptions>(options => |
|||
{ |
|||
options.InputQueueName = "eventbus"; |
|||
options.Configurer = rebusConfigurer => |
|||
{ |
|||
rebusConfigurer.Transport(t => t.UseInMemoryTransport(new InMemNetwork(), "eventbus")); |
|||
rebusConfigurer.Subscriptions(s => s.StoreInMemory()); |
|||
}; |
|||
}); |
|||
} |
|||
|
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
context.Services.AddMongoDbContext<TodoMongoDbContext>(options => |
|||
{ |
|||
options.AddDefaultRepositories(); |
|||
}); |
|||
|
|||
Configure<AbpDistributedEventBusOptions>(options => |
|||
{ |
|||
options.Outboxes.Configure(config => |
|||
{ |
|||
config.UseMongoDbContext<TodoMongoDbContext>(); |
|||
}); |
|||
|
|||
options.Inboxes.Configure(config => |
|||
{ |
|||
config.UseMongoDbContext<TodoMongoDbContext>(); |
|||
}); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,57 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Hosting; |
|||
using Serilog; |
|||
using Serilog.Events; |
|||
|
|||
namespace DistDemoApp |
|||
{ |
|||
public class Program |
|||
{ |
|||
public static async Task<int> Main(string[] args) |
|||
{ |
|||
Log.Logger = new LoggerConfiguration() |
|||
#if DEBUG
|
|||
.MinimumLevel.Debug() |
|||
#else
|
|||
.MinimumLevel.Information() |
|||
#endif
|
|||
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning) |
|||
.Enrich.FromLogContext() |
|||
.WriteTo.Async(c => c.File("Logs/logs.txt")) |
|||
.WriteTo.Async(c => c.Console()) |
|||
.CreateLogger(); |
|||
|
|||
try |
|||
{ |
|||
Log.Information("Starting console host."); |
|||
await CreateHostBuilder(args).RunConsoleAsync(); |
|||
return 0; |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Log.Fatal(ex, "Host terminated unexpectedly!"); |
|||
return 1; |
|||
} |
|||
finally |
|||
{ |
|||
Log.CloseAndFlush(); |
|||
} |
|||
|
|||
} |
|||
|
|||
internal static IHostBuilder CreateHostBuilder(string[] args) => |
|||
Host.CreateDefaultBuilder(args) |
|||
.UseAutofac() |
|||
.UseSerilog() |
|||
.ConfigureAppConfiguration((context, config) => |
|||
{ |
|||
//setup your additional configuration sources
|
|||
}) |
|||
.ConfigureServices((hostContext, services) => |
|||
{ |
|||
services.AddApplication<DistDemoAppMongoDbRebusModule>(); |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
using MongoDB.Driver; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.MongoDB; |
|||
using Volo.Abp.MongoDB.DistributedEvents; |
|||
|
|||
namespace DistDemoApp |
|||
{ |
|||
[ConnectionStringName("Default")] |
|||
public class TodoMongoDbContext : AbpMongoDbContext, IHasEventOutbox, IHasEventInbox |
|||
{ |
|||
public IMongoCollection<TodoItem> TodoItems => Collection<TodoItem>(); |
|||
public IMongoCollection<TodoSummary> TodoSummaries => Collection<TodoSummary>(); |
|||
|
|||
public IMongoCollection<OutgoingEventRecord> OutgoingEvents => Collection<OutgoingEventRecord>(); |
|||
|
|||
public IMongoCollection<IncomingEventRecord> IncomingEvents => Collection<IncomingEventRecord>(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
{ |
|||
"ConnectionStrings": { |
|||
"Default": "mongodb://localhost:27018,localhost:27019,localhost:27020/DistEventsDemo" |
|||
}, |
|||
"Kafka": { |
|||
"Connections": { |
|||
"Default": { |
|||
"BootstrapServers": "localhost:9092" |
|||
} |
|||
}, |
|||
"EventBus": { |
|||
"GroupId": "DistDemoApp", |
|||
"TopicName": "DistDemoTopic" |
|||
} |
|||
}, |
|||
"Redis": { |
|||
"Configuration": "127.0.0.1" |
|||
} |
|||
} |
|||
Loading…
Reference in new issue