mirror of https://github.com/abpframework/abp.git
26 changed files with 371 additions and 18 deletions
@ -0,0 +1,29 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
using Volo.Abp.Guids; |
|||
|
|||
namespace Volo.Abp.EntityFrameworkCore.DistributedEvents |
|||
{ |
|||
public class DbContextEventOutbox<TDbContext> : IEventOutbox |
|||
where TDbContext : IHasEventOutbox |
|||
{ |
|||
protected IDbContextProvider<TDbContext> DbContextProvider { get; } |
|||
protected IGuidGenerator GuidGenerator { get; } |
|||
|
|||
public DbContextEventOutbox( |
|||
IDbContextProvider<TDbContext> dbContextProvider, |
|||
IGuidGenerator guidGenerator) |
|||
{ |
|||
DbContextProvider = dbContextProvider; |
|||
GuidGenerator = guidGenerator; |
|||
} |
|||
|
|||
public async Task EnqueueAsync(string eventName, byte[] eventData) |
|||
{ |
|||
var dbContext = (IHasEventOutbox) await DbContextProvider.GetDbContextAsync(); |
|||
dbContext.OutgoingEventRecords.Add( |
|||
new OutgoingEventRecord(GuidGenerator.Create(), eventName, eventData) |
|||
); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.EventBus.Rebus |
|||
{ |
|||
public interface IRebusSerializer |
|||
{ |
|||
byte[] Serialize(object obj); |
|||
|
|||
object Deserialize(byte[] value, Type type); |
|||
|
|||
T Deserialize<T>(byte[] value); |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
using System; |
|||
using System.Text; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Json; |
|||
|
|||
namespace Volo.Abp.EventBus.Rebus |
|||
{ |
|||
public class Utf8JsonRebusSerializer : IRebusSerializer, ITransientDependency |
|||
{ |
|||
private readonly IJsonSerializer _jsonSerializer; |
|||
|
|||
public Utf8JsonRebusSerializer(IJsonSerializer jsonSerializer) |
|||
{ |
|||
_jsonSerializer = jsonSerializer; |
|||
} |
|||
|
|||
public byte[] Serialize(object obj) |
|||
{ |
|||
return Encoding.UTF8.GetBytes(_jsonSerializer.Serialize(obj)); |
|||
} |
|||
|
|||
public object Deserialize(byte[] value, Type type) |
|||
{ |
|||
return _jsonSerializer.Deserialize(type, Encoding.UTF8.GetString(value)); |
|||
} |
|||
|
|||
public T Deserialize<T>(byte[] value) |
|||
{ |
|||
return _jsonSerializer.Deserialize<T>(Encoding.UTF8.GetString(value)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.EventBus.Distributed |
|||
{ |
|||
public interface IEventOutbox |
|||
{ |
|||
Task EnqueueAsync(string eventName, byte[] eventData); |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.EventBus.Distributed |
|||
{ |
|||
public class OutboxConfig |
|||
{ |
|||
public string Name { get; } |
|||
|
|||
public Type ImplementationType { get; set; } |
|||
public Func<Type, bool> Selector { get; set; } |
|||
|
|||
public OutboxConfig(string name, Type implementationType, Func<Type, bool> selector = null) |
|||
{ |
|||
Name = name; |
|||
ImplementationType = implementationType; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.EventBus.Distributed |
|||
{ |
|||
public class OutboxConfigList : List<OutboxConfig> |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,118 @@ |
|||
// <auto-generated />
|
|||
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("20210908063422_Added_Outbox")] |
|||
partial class Added_Outbox |
|||
{ |
|||
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<Guid>("Id") |
|||
.HasColumnType("uniqueidentifier"); |
|||
|
|||
b.Property<string>("ConcurrencyStamp") |
|||
.IsConcurrencyToken() |
|||
.HasMaxLength(40) |
|||
.HasColumnType("nvarchar(40)") |
|||
.HasColumnName("ConcurrencyStamp"); |
|||
|
|||
b.Property<DateTime>("CreationTime") |
|||
.HasColumnType("datetime2") |
|||
.HasColumnName("CreationTime"); |
|||
|
|||
b.Property<Guid?>("CreatorId") |
|||
.HasColumnType("uniqueidentifier") |
|||
.HasColumnName("CreatorId"); |
|||
|
|||
b.Property<string>("ExtraProperties") |
|||
.HasColumnType("nvarchar(max)") |
|||
.HasColumnName("ExtraProperties"); |
|||
|
|||
b.Property<string>("Text") |
|||
.IsRequired() |
|||
.HasMaxLength(128) |
|||
.HasColumnType("nvarchar(128)"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.ToTable("TodoItems"); |
|||
}); |
|||
|
|||
modelBuilder.Entity("DistDemoApp.TodoSummary", b => |
|||
{ |
|||
b.Property<int>("Id") |
|||
.ValueGeneratedOnAdd() |
|||
.HasColumnType("int") |
|||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); |
|||
|
|||
b.Property<string>("ConcurrencyStamp") |
|||
.IsConcurrencyToken() |
|||
.HasMaxLength(40) |
|||
.HasColumnType("nvarchar(40)") |
|||
.HasColumnName("ConcurrencyStamp"); |
|||
|
|||
b.Property<byte>("Day") |
|||
.HasColumnType("tinyint"); |
|||
|
|||
b.Property<string>("ExtraProperties") |
|||
.HasColumnType("nvarchar(max)") |
|||
.HasColumnName("ExtraProperties"); |
|||
|
|||
b.Property<byte>("Month") |
|||
.HasColumnType("tinyint"); |
|||
|
|||
b.Property<int>("TotalCount") |
|||
.HasColumnType("int"); |
|||
|
|||
b.Property<int>("Year") |
|||
.HasColumnType("int"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.ToTable("TodoSummaries"); |
|||
}); |
|||
|
|||
modelBuilder.Entity("Volo.Abp.EntityFrameworkCore.DistributedEvents.OutgoingEventRecord", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.HasColumnType("uniqueidentifier"); |
|||
|
|||
b.Property<byte[]>("EventData") |
|||
.IsRequired() |
|||
.HasColumnType("varbinary(max)"); |
|||
|
|||
b.Property<string>("EventName") |
|||
.IsRequired() |
|||
.HasMaxLength(256) |
|||
.HasColumnType("nvarchar(256)"); |
|||
|
|||
b.Property<string>("ExtraProperties") |
|||
.HasColumnType("nvarchar(max)") |
|||
.HasColumnName("ExtraProperties"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.ToTable("AbpEventOutbox"); |
|||
}); |
|||
#pragma warning restore 612, 618
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
namespace DistDemoApp.Migrations |
|||
{ |
|||
public partial class Added_Outbox : Migration |
|||
{ |
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.CreateTable( |
|||
name: "AbpEventOutbox", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), |
|||
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
EventName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false), |
|||
EventData = table.Column<byte[]>(type: "varbinary(max)", nullable: false) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_AbpEventOutbox", x => x.Id); |
|||
}); |
|||
} |
|||
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropTable( |
|||
name: "AbpEventOutbox"); |
|||
} |
|||
} |
|||
} |
|||
@ -1,5 +1,16 @@ |
|||
{ |
|||
"ConnectionStrings": { |
|||
"Default": "Server=(LocalDb)\\MSSQLLocalDB;Database=DistEventsDemo;Trusted_Connection=True" |
|||
}, |
|||
"RabbitMQ": { |
|||
"Connections": { |
|||
"Default": { |
|||
"HostName": "localhost" |
|||
} |
|||
}, |
|||
"EventBus": { |
|||
"ClientName": "DistDemoApp", |
|||
"ExchangeName": "DistDemo" |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue