mirror of https://github.com/abpframework/abp.git
38 changed files with 543 additions and 132 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,47 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.Extensions.Options; |
|||
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<AbpDistributedEventBusOptions> distributedEventsOptions) : base(dbContextProvider, clock, distributedEventsOptions) |
|||
{ |
|||
} |
|||
|
|||
[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.Add(DistributedEventsOptions.InboxKeepEventTimeSpan); |
|||
|
|||
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,47 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.Extensions.Options; |
|||
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<AbpDistributedEventBusOptions> distributedEventsOptions) : base(dbContextProvider, clock, distributedEventsOptions) |
|||
{ |
|||
} |
|||
|
|||
[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.Add(DistributedEventsOptions.InboxKeepEventTimeSpan); |
|||
|
|||
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 |
|||
{ |
|||
} |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents |
|||
{ |
|||
public class PostgreSqlAdapter : ISqlAdapter |
|||
{ |
|||
public string NormalizeTableName(string tableName) |
|||
{ |
|||
return $"\"{tableName}\""; |
|||
} |
|||
|
|||
public string NormalizeColumnName(string columnName) |
|||
{ |
|||
return $"\"{columnName}\""; |
|||
} |
|||
|
|||
public string NormalizeColumnNameEqualsValue(string columnName, object value) |
|||
{ |
|||
return $"\"{columnName}\" = '{value}'"; |
|||
} |
|||
|
|||
public string NormalizeValue(object value) |
|||
{ |
|||
return $"'{value}'"; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.Extensions.Options; |
|||
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<AbpDistributedEventBusOptions> distributedEventsOptions) |
|||
: base(dbContextProvider, clock, distributedEventsOptions) |
|||
{ |
|||
} |
|||
|
|||
[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.Add(DistributedEventsOptions.InboxKeepEventTimeSpan); |
|||
|
|||
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 UsePostgreSql<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 UsePostgreSql<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>); |
|||
} |
|||
} |
|||
} |
|||
@ -1,19 +0,0 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents |
|||
{ |
|||
public class AbpEfCoreDistributedEventBusOptions |
|||
{ |
|||
public Dictionary<string, ISqlAdapter> SqlAdapters { get; set; } |
|||
|
|||
public ISqlAdapter GetSqlAdapter(string connectionType) |
|||
{ |
|||
return SqlAdapters.TryGetValue(connectionType, out var sqlAdapter) ? sqlAdapter : SqlAdapters[DefaultSqlAdapter.Name]; |
|||
} |
|||
|
|||
public AbpEfCoreDistributedEventBusOptions() |
|||
{ |
|||
SqlAdapters = new Dictionary<string, ISqlAdapter>(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,27 +0,0 @@ |
|||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents |
|||
{ |
|||
public class DefaultSqlAdapter : ISqlAdapter |
|||
{ |
|||
public const string Name = "default"; |
|||
|
|||
public string NormalizeTableName(string tableName) |
|||
{ |
|||
return tableName; |
|||
} |
|||
|
|||
public string NormalizeColumnName(string columnName) |
|||
{ |
|||
return columnName; |
|||
} |
|||
|
|||
public string NormalizeColumnNameEqualsValue(string columnName, object value) |
|||
{ |
|||
return $"{columnName} = '{value}'"; |
|||
} |
|||
|
|||
public string NormalizeValue(object value) |
|||
{ |
|||
return $"'{value}'"; |
|||
} |
|||
} |
|||
} |
|||
@ -1,13 +0,0 @@ |
|||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents |
|||
{ |
|||
public interface ISqlAdapter |
|||
{ |
|||
string NormalizeTableName(string tableName); |
|||
|
|||
string NormalizeColumnName(string columnName); |
|||
|
|||
string NormalizeColumnNameEqualsValue(string columnName, object value); |
|||
|
|||
string NormalizeValue(object value); |
|||
} |
|||
} |
|||
@ -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.Distributed; |
|||
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<AbpDistributedEventBusOptions> distributedEventsOptions) |
|||
: base(dbContextProvider, clock, distributedEventsOptions) |
|||
{ |
|||
} |
|||
|
|||
[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.Add(DistributedEventsOptions.InboxKeepEventTimeSpan); |
|||
|
|||
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}'"; |
|||
await dbContext.Database.ExecuteSqlRawAsync(sql); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue