diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/EfCoreOutboxConfigExtensions.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/EfCoreOutboxConfigExtensions.cs new file mode 100644 index 0000000000..8199ff0739 --- /dev/null +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/EfCoreOutboxConfigExtensions.cs @@ -0,0 +1,13 @@ +using Volo.Abp.EventBus.Distributed; + +namespace Volo.Abp.EntityFrameworkCore.DistributedEvents +{ + public static class EfCoreOutboxConfigExtensions + { + public static void UseDbContext(this OutboxConfig outboxConfig) + where TDbContext : IHasEventOutbox + { + outboxConfig.ImplementationType = typeof(DbContextEventOutbox); + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/OutgoingEventRecord.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/OutgoingEventRecord.cs index 395970c4a9..d33e6a0097 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/OutgoingEventRecord.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DistributedEvents/OutgoingEventRecord.cs @@ -1,17 +1,21 @@ using System; +using Volo.Abp.Auditing; using Volo.Abp.Data; using Volo.Abp.Domain.Entities; namespace Volo.Abp.EntityFrameworkCore.DistributedEvents { - public class OutgoingEventRecord : BasicAggregateRoot, IHasExtraProperties + public class OutgoingEventRecord : BasicAggregateRoot, IHasExtraProperties, IHasCreationTime { public static int MaxEventNameLength { get; set; } = 256; public ExtraPropertyDictionary ExtraProperties { get; protected set; } public string EventName { get; set; } + public byte[] EventData { get; set; } + + public DateTime CreationTime { get; set; } protected OutgoingEventRecord() { diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/DistributedEventBusBase.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/DistributedEventBusBase.cs index bea6b93a36..3d68490ae2 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/DistributedEventBusBase.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/DistributedEventBusBase.cs @@ -80,7 +80,7 @@ namespace Volo.Abp.EventBus.Distributed return false; } - foreach (var outboxConfig in AbpDistributedEventBusOptions.Outboxes) + foreach (var outboxConfig in AbpDistributedEventBusOptions.Outboxes.Values) { if (outboxConfig.Selector == null || outboxConfig.Selector(eventType)) { diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/OutboxConfig.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/OutboxConfig.cs index 97712ec85e..be7630ddee 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/OutboxConfig.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/OutboxConfig.cs @@ -1,18 +1,26 @@ using System; +using JetBrains.Annotations; namespace Volo.Abp.EventBus.Distributed { public class OutboxConfig { + [NotNull] public string Name { get; } public Type ImplementationType { get; set; } + public Func Selector { get; set; } - public OutboxConfig(string name, Type implementationType, Func selector = null) + /// + /// Used to enable/disable sending events from outbox to the message broker. + /// Default: true. + /// + public bool IsSendingEnabled { get; set; } = true; + + public OutboxConfig([NotNull] string name) { - Name = name; - ImplementationType = implementationType; + Name = Check.NotNullOrWhiteSpace(name, nameof(name)); } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/OutboxConfigList.cs b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/OutboxConfigList.cs index 47c91377da..162ceef6ff 100644 --- a/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/OutboxConfigList.cs +++ b/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/OutboxConfigList.cs @@ -1,8 +1,14 @@ +using System; using System.Collections.Generic; namespace Volo.Abp.EventBus.Distributed { - public class OutboxConfigList : List + public class OutboxConfigList : Dictionary { + public void Configure(string outboxName, Action configAction) + { + var outboxConfig = this.GetOrAdd(outboxName, () => new OutboxConfig(outboxName)); + configAction(outboxConfig); + } } } \ No newline at end of file diff --git a/test/DistEvents/DistDemoApp/DistDemoAppModule.cs b/test/DistEvents/DistDemoApp/DistDemoAppModule.cs index 3cb92b2307..93880032d9 100644 --- a/test/DistEvents/DistDemoApp/DistDemoAppModule.cs +++ b/test/DistEvents/DistDemoApp/DistDemoAppModule.cs @@ -39,9 +39,10 @@ namespace DistDemoApp Configure(options => { - options.Outboxes.Add( - new OutboxConfig("Default", typeof(DbContextEventOutbox)) - ); + options.Outboxes.Configure("Default", config => + { + config.UseDbContext(); + }); }); } } diff --git a/test/DistEvents/DistDemoApp/Migrations/20210908075344_Added_Outbox_CreationTime.Designer.cs b/test/DistEvents/DistDemoApp/Migrations/20210908075344_Added_Outbox_CreationTime.Designer.cs new file mode 100644 index 0000000000..def5ebc7d7 --- /dev/null +++ b/test/DistEvents/DistDemoApp/Migrations/20210908075344_Added_Outbox_CreationTime.Designer.cs @@ -0,0 +1,122 @@ +// +using System; +using DistDemoApp; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Volo.Abp.EntityFrameworkCore; + +namespace DistDemoApp.Migrations +{ + [DbContext(typeof(TodoDbContext))] + [Migration("20210908075344_Added_Outbox_CreationTime")] + partial class Added_Outbox_CreationTime + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.SqlServer) + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("ProductVersion", "5.0.9") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("DistDemoApp.TodoItem", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasMaxLength(40) + .HasColumnType("nvarchar(40)") + .HasColumnName("ConcurrencyStamp"); + + b.Property("CreationTime") + .HasColumnType("datetime2") + .HasColumnName("CreationTime"); + + b.Property("CreatorId") + .HasColumnType("uniqueidentifier") + .HasColumnName("CreatorId"); + + b.Property("ExtraProperties") + .HasColumnType("nvarchar(max)") + .HasColumnName("ExtraProperties"); + + b.Property("Text") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.HasKey("Id"); + + b.ToTable("TodoItems"); + }); + + modelBuilder.Entity("DistDemoApp.TodoSummary", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasMaxLength(40) + .HasColumnType("nvarchar(40)") + .HasColumnName("ConcurrencyStamp"); + + b.Property("Day") + .HasColumnType("tinyint"); + + b.Property("ExtraProperties") + .HasColumnType("nvarchar(max)") + .HasColumnName("ExtraProperties"); + + b.Property("Month") + .HasColumnType("tinyint"); + + b.Property("TotalCount") + .HasColumnType("int"); + + b.Property("Year") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("TodoSummaries"); + }); + + modelBuilder.Entity("Volo.Abp.EntityFrameworkCore.DistributedEvents.OutgoingEventRecord", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("CreationTime") + .HasColumnType("datetime2") + .HasColumnName("CreationTime"); + + b.Property("EventData") + .IsRequired() + .HasColumnType("varbinary(max)"); + + b.Property("EventName") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("ExtraProperties") + .HasColumnType("nvarchar(max)") + .HasColumnName("ExtraProperties"); + + b.HasKey("Id"); + + b.ToTable("AbpEventOutbox"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/test/DistEvents/DistDemoApp/Migrations/20210908075344_Added_Outbox_CreationTime.cs b/test/DistEvents/DistDemoApp/Migrations/20210908075344_Added_Outbox_CreationTime.cs new file mode 100644 index 0000000000..2899933b8f --- /dev/null +++ b/test/DistEvents/DistDemoApp/Migrations/20210908075344_Added_Outbox_CreationTime.cs @@ -0,0 +1,25 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace DistDemoApp.Migrations +{ + public partial class Added_Outbox_CreationTime : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "CreationTime", + table: "AbpEventOutbox", + type: "datetime2", + nullable: false, + defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "CreationTime", + table: "AbpEventOutbox"); + } + } +} diff --git a/test/DistEvents/DistDemoApp/Migrations/TodoDbContextModelSnapshot.cs b/test/DistEvents/DistDemoApp/Migrations/TodoDbContextModelSnapshot.cs index 91d7bc0cc7..f1b3330485 100644 --- a/test/DistEvents/DistDemoApp/Migrations/TodoDbContextModelSnapshot.cs +++ b/test/DistEvents/DistDemoApp/Migrations/TodoDbContextModelSnapshot.cs @@ -93,6 +93,10 @@ namespace DistDemoApp.Migrations b.Property("Id") .HasColumnType("uniqueidentifier"); + b.Property("CreationTime") + .HasColumnType("datetime2") + .HasColumnName("CreationTime"); + b.Property("EventData") .IsRequired() .HasColumnType("varbinary(max)");