mirror of https://github.com/abpframework/abp.git
25 changed files with 563 additions and 71 deletions
@ -0,0 +1,43 @@ |
|||
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>
|
|||
/// Delay time of <see cref="InboxProcessor"/> and <see cref="OutboxSender"/>
|
|||
/// Default: 15 seconds
|
|||
/// </summary>
|
|||
public TimeSpan DelayTimeSpan { get; set; } |
|||
|
|||
public AbpEventBusBoxesOptions() |
|||
{ |
|||
CleanOldEventTimeIntervalSpan = TimeSpan.FromHours(6); |
|||
InboxWaitingEventMaxCount = 1000; |
|||
OutboxWaitingEventMaxCount = 1000; |
|||
PeriodTimeSpan = TimeSpan.FromSeconds(2); |
|||
DelayTimeSpan = TimeSpan.FromSeconds(15); |
|||
} |
|||
} |
|||
} |
|||
@ -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 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 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 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,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" |
|||
} |
|||
} |
|||
Loading…
Reference in new issue