Larger Refactoring of IntegrationEvents

This commit is contained in:
Cesar De la Torre 2017-03-15 18:42:47 -07:00
parent e41ce96f81
commit 8423c8bb63
20 changed files with 262 additions and 68 deletions

View File

@ -12,6 +12,10 @@
<DockerComposeProjectPath>..\..\..\..\docker-compose.dcproj</DockerComposeProjectPath> <DockerComposeProjectPath>..\..\..\..\docker-compose.dcproj</DockerComposeProjectPath>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Compile Include="IntegrationEvents\Events\ProductPriceChangedEvent.cs.txt" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<Content Update="web.config"> <Content Update="web.config">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
@ -23,16 +27,16 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="System.Threading" Version="4.3.0" /> <PackageReference Include="System.Threading" Version="4.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.0" /> <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.0" /> <PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.0" /> <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.1.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.0" /> <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
<PackageReference Include="StackExchange.Redis" Version="1.1.608" /> <PackageReference Include="StackExchange.Redis" Version="1.1.608" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="1.0.1-rc3" /> <PackageReference Include="IdentityServer4.AccessTokenValidation" Version="1.0.1-rc3" />

View File

@ -6,17 +6,17 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Basket.API.Events namespace Basket.API.IntegrationEvents.EventHandling
{ {
public class ProductPriceChangedHandler : IIntegrationEventHandler<ProductPriceChanged> public class ProductPriceChangedEventHandler : IIntegrationEventHandler<ProductPriceChangedEvent>
{ {
private readonly IBasketRepository _repository; private readonly IBasketRepository _repository;
public ProductPriceChangedHandler(IBasketRepository repository) public ProductPriceChangedEventHandler(IBasketRepository repository)
{ {
_repository = repository; _repository = repository;
} }
public async Task Handle(ProductPriceChanged @event) public async Task Handle(ProductPriceChangedEvent @event)
{ {
var userIds = await _repository.GetUsers(); var userIds = await _repository.GetUsers();
foreach (var id in userIds) foreach (var id in userIds)

View File

@ -0,0 +1,3 @@

// To implement ProductPriceChangedEvent.cs here

View File

@ -15,7 +15,7 @@ using Swashbuckle.Swagger.Model;
using Microsoft.eShopOnContainers.Services.Basket.API.Auth.Server; using Microsoft.eShopOnContainers.Services.Basket.API.Auth.Server;
using Microsoft.eShopOnContainers.Services.Common.Infrastructure; using Microsoft.eShopOnContainers.Services.Common.Infrastructure;
using Microsoft.eShopOnContainers.Services.Common.Infrastructure.Catalog; using Microsoft.eShopOnContainers.Services.Common.Infrastructure.Catalog;
using Basket.API.Events; using Basket.API.IntegrationEvents.EventHandling;
namespace Microsoft.eShopOnContainers.Services.Basket.API namespace Microsoft.eShopOnContainers.Services.Basket.API
{ {
@ -79,7 +79,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
}); });
services.AddTransient<IBasketRepository, RedisBasketRepository>(); services.AddTransient<IBasketRepository, RedisBasketRepository>();
services.AddTransient<IIntegrationEventHandler<ProductPriceChanged>, ProductPriceChangedHandler>(); services.AddTransient<IIntegrationEventHandler<ProductPriceChangedEvent>, ProductPriceChangedEventHandler>();
var serviceProvider = services.BuildServiceProvider(); var serviceProvider = services.BuildServiceProvider();
var configuration = serviceProvider.GetRequiredService<IOptionsSnapshot<BasketSettings>>().Value; var configuration = serviceProvider.GetRequiredService<IOptionsSnapshot<BasketSettings>>().Value;
@ -87,8 +87,8 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
services.AddSingleton<IEventBus>(eventBus); services.AddSingleton<IEventBus>(eventBus);
var catalogPriceHandler = serviceProvider.GetService<IIntegrationEventHandler<ProductPriceChanged>>(); var catalogPriceHandler = serviceProvider.GetService<IIntegrationEventHandler<ProductPriceChangedEvent>>();
eventBus.Subscribe<ProductPriceChanged>(catalogPriceHandler); eventBus.Subscribe<ProductPriceChangedEvent>(catalogPriceHandler);
} }

View File

@ -21,6 +21,8 @@
<Content Include="Pics\**\*;"> <Content Include="Pics\**\*;">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content> </Content>
<Compile Include="IntegrationEvents\EventHandling\AnyFutureIntegrationEventHandler.cs.txt" />
<Compile Include="IntegrationEvents\Events\ProductPriceChangedEvent.cs.txt" />
<Content Update="web.config;"> <Content Update="web.config;">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content> </Content>
@ -28,23 +30,24 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.0" /> <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.0" /> <PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.Abstractions" Version="1.1.0" /> <PackageReference Include="Microsoft.AspNetCore.Diagnostics.Abstractions" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.0" /> <PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.0" /> <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.1.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.0" /> <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="1.1.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="Swashbuckle" Version="6.0.0-beta902" /> <PackageReference Include="Swashbuckle" Version="6.0.0-beta902" />
</ItemGroup> </ItemGroup>

View File

@ -149,7 +149,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
_context.CatalogItems.Update(item); _context.CatalogItems.Update(item);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
var @event = new ProductPriceChanged(item.Id, item.Price, oldPrice); var @event = new ProductPriceChangedEvent(item.Id, item.Price, oldPrice);
await ProcessEventAsync(@event); await ProcessEventAsync(@event);
} }
@ -166,14 +166,14 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
return items; return items;
} }
private async Task ProcessEventAsync(IntegrationEventBase @event) private async Task ProcessEventAsync(IntegrationEvent @event)
{ {
_eventBus.Publish(@event); _eventBus.Publish(@event);
var eventData = new IntegrationEvent(@event); var eventLogEntry = new IntegrationEventLogEntry(@event);
eventData.TimesSent++; eventLogEntry.TimesSent++;
eventData.State = EventStateEnum.Sent; eventLogEntry.State = EventStateEnum.Published;
_context.IntegrationEvents.Add(eventData); _context.IntegrationEventLog.Add(eventLogEntry);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
} }

View File

@ -13,14 +13,14 @@
public DbSet<CatalogItem> CatalogItems { get; set; } public DbSet<CatalogItem> CatalogItems { get; set; }
public DbSet<CatalogBrand> CatalogBrands { get; set; } public DbSet<CatalogBrand> CatalogBrands { get; set; }
public DbSet<CatalogType> CatalogTypes { get; set; } public DbSet<CatalogType> CatalogTypes { get; set; }
public DbSet<IntegrationEvent> IntegrationEvents { get; set; } public DbSet<IntegrationEventLogEntry> IntegrationEventLog { get; set; }
protected override void OnModelCreating(ModelBuilder builder) protected override void OnModelCreating(ModelBuilder builder)
{ {
builder.Entity<CatalogBrand>(ConfigureCatalogBrand); builder.Entity<CatalogBrand>(ConfigureCatalogBrand);
builder.Entity<CatalogType>(ConfigureCatalogType); builder.Entity<CatalogType>(ConfigureCatalogType);
builder.Entity<CatalogItem>(ConfigureCatalogItem); builder.Entity<CatalogItem>(ConfigureCatalogItem);
builder.Entity<IntegrationEvent>(ConfigureIntegrationEvent); builder.Entity<IntegrationEventLogEntry>(ConfigureIntegrationEventLogEntry);
} }
void ConfigureCatalogItem(EntityTypeBuilder<CatalogItem> builder) void ConfigureCatalogItem(EntityTypeBuilder<CatalogItem> builder)
@ -80,9 +80,9 @@
.HasMaxLength(100); .HasMaxLength(100);
} }
void ConfigureIntegrationEvent(EntityTypeBuilder<IntegrationEvent> builder) void ConfigureIntegrationEventLogEntry(EntityTypeBuilder<IntegrationEventLogEntry> builder)
{ {
builder.ToTable("IntegrationEvent"); builder.ToTable("IntegrationEventLog");
builder.HasKey(e => e.EventId); builder.HasKey(e => e.EventId);

View File

@ -0,0 +1,122 @@
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
using Microsoft.eShopOnContainers.Services.Common.Infrastructure;
namespace Catalog.API.Infrastructure.Migrations
{
[DbContext(typeof(CatalogContext))]
[Migration("20170316012921_RefactoringToIntegrationEventLog")]
partial class RefactoringToIntegrationEventLog
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "1.1.1")
.HasAnnotation("SqlServer:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'")
.HasAnnotation("SqlServer:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'")
.HasAnnotation("SqlServer:Sequence:.catalog_type_hilo", "'catalog_type_hilo', '', '1', '10', '', '', 'Int64', 'False'")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogBrand", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_brand_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<string>("Brand")
.IsRequired()
.HasMaxLength(100);
b.HasKey("Id");
b.ToTable("CatalogBrand");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<int>("CatalogBrandId");
b.Property<int>("CatalogTypeId");
b.Property<string>("Description");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50);
b.Property<string>("PictureUri");
b.Property<decimal>("Price");
b.HasKey("Id");
b.HasIndex("CatalogBrandId");
b.HasIndex("CatalogTypeId");
b.ToTable("Catalog");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogType", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_type_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<string>("Type")
.IsRequired()
.HasMaxLength(100);
b.HasKey("Id");
b.ToTable("CatalogType");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Common.Infrastructure.Data.IntegrationEventLogEntry", b =>
{
b.Property<Guid>("EventId")
.ValueGeneratedOnAdd();
b.Property<string>("Content")
.IsRequired();
b.Property<DateTime>("CreationTime");
b.Property<string>("EventTypeName")
.IsRequired();
b.Property<int>("State");
b.Property<int>("TimesSent");
b.HasKey("EventId");
b.ToTable("IntegrationEventLog");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogItem", b =>
{
b.HasOne("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogBrand", "CatalogBrand")
.WithMany()
.HasForeignKey("CatalogBrandId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogType", "CatalogType")
.WithMany()
.HasForeignKey("CatalogTypeId")
.OnDelete(DeleteBehavior.Cascade);
});
}
}
}

View File

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Catalog.API.Infrastructure.Migrations
{
public partial class RefactoringToIntegrationEventLog : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "IntegrationEvent");
migrationBuilder.CreateTable(
name: "IntegrationEventLog",
columns: table => new
{
EventId = table.Column<Guid>(nullable: false),
Content = table.Column<string>(nullable: false),
CreationTime = table.Column<DateTime>(nullable: false),
EventTypeName = table.Column<string>(nullable: false),
State = table.Column<int>(nullable: false),
TimesSent = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_IntegrationEventLog", x => x.EventId);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "IntegrationEventLog");
migrationBuilder.CreateTable(
name: "IntegrationEvent",
columns: table => new
{
EventId = table.Column<Guid>(nullable: false),
Content = table.Column<string>(nullable: false),
CreationTime = table.Column<DateTime>(nullable: false),
EventTypeName = table.Column<string>(maxLength: 200, nullable: false),
State = table.Column<int>(nullable: false),
TimesSent = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_IntegrationEvent", x => x.EventId);
});
}
}
}

View File

@ -14,7 +14,7 @@ namespace Catalog.API.Infrastructure.Migrations
protected override void BuildModel(ModelBuilder modelBuilder) protected override void BuildModel(ModelBuilder modelBuilder)
{ {
modelBuilder modelBuilder
.HasAnnotation("ProductVersion", "1.1.0-rtm-22752") .HasAnnotation("ProductVersion", "1.1.1")
.HasAnnotation("SqlServer:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'") .HasAnnotation("SqlServer:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'")
.HasAnnotation("SqlServer:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'") .HasAnnotation("SqlServer:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'")
.HasAnnotation("SqlServer:Sequence:.catalog_type_hilo", "'catalog_type_hilo', '', '1', '10', '', '', 'Int64', 'False'") .HasAnnotation("SqlServer:Sequence:.catalog_type_hilo", "'catalog_type_hilo', '', '1', '10', '', '', 'Int64', 'False'")
@ -82,7 +82,7 @@ namespace Catalog.API.Infrastructure.Migrations
b.ToTable("CatalogType"); b.ToTable("CatalogType");
}); });
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Common.Infrastructure.Data.IntegrationEvent", b => modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Common.Infrastructure.Data.IntegrationEventLogEntry", b =>
{ {
b.Property<Guid>("EventId") b.Property<Guid>("EventId")
.ValueGeneratedOnAdd(); .ValueGeneratedOnAdd();
@ -93,8 +93,7 @@ namespace Catalog.API.Infrastructure.Migrations
b.Property<DateTime>("CreationTime"); b.Property<DateTime>("CreationTime");
b.Property<string>("EventTypeName") b.Property<string>("EventTypeName")
.IsRequired() .IsRequired();
.HasMaxLength(200);
b.Property<int>("State"); b.Property<int>("State");
@ -102,7 +101,7 @@ namespace Catalog.API.Infrastructure.Migrations
b.HasKey("EventId"); b.HasKey("EventId");
b.ToTable("IntegrationEvent"); b.ToTable("IntegrationEventLog");
}); });
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogItem", b => modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogItem", b =>

View File

@ -0,0 +1,3 @@

// To implement ProductPriceChangedEvent.cs here

View File

@ -0,0 +1,3 @@

// To implement any future integration event handler here

View File

@ -4,7 +4,10 @@ using System.Text;
namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure.Catalog namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure.Catalog
{ {
public class ProductPriceChanged : IntegrationEventBase // Integration Events notes:
// An Event is “something that has happened in the past”, therefore its name has to be
// An Integration Event is an event that can cause side effects to other microsrvices, Bounded-Contexts or external systems.
public class ProductPriceChangedEvent : IntegrationEvent
{ {
public int ProductId { get; private set; } public int ProductId { get; private set; }
@ -12,11 +15,11 @@ namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure.Catalog
public decimal OldPrice { get; private set; } public decimal OldPrice { get; private set; }
public ProductPriceChanged(int productId, decimal newPrice, decimal oldPrice) public ProductPriceChangedEvent(int productId, decimal newPrice, decimal oldPrice)
{ {
ProductId = productId; ProductId = productId;
NewPrice = newPrice; NewPrice = newPrice;
OldPrice = oldPrice; OldPrice = oldPrice;
} }
} }
} }

View File

@ -6,8 +6,8 @@ namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure
{ {
public enum EventStateEnum public enum EventStateEnum
{ {
NotSend = 0, NotPublished = 0,
Sent = 1, Published = 1,
SendingFailed = 2 PublishedFailed = 2
} }
} }

View File

@ -5,15 +5,15 @@ using Newtonsoft.Json;
namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure.Data namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure.Data
{ {
public class IntegrationEvent public class IntegrationEventLogEntry
{ {
public IntegrationEvent(IntegrationEventBase @event) public IntegrationEventLogEntry(IntegrationEvent @event)
{ {
EventId = @event.Id; EventId = @event.Id;
CreationTime = DateTime.UtcNow; CreationTime = DateTime.UtcNow;
EventTypeName = @event.GetType().FullName; EventTypeName = @event.GetType().FullName;
Content = JsonConvert.SerializeObject(@event); Content = JsonConvert.SerializeObject(@event);
State = EventStateEnum.NotSend; State = EventStateEnum.NotPublished;
TimesSent = 0; TimesSent = 0;
} }
public Guid EventId { get; private set; } public Guid EventId { get; private set; }

View File

@ -30,7 +30,7 @@ namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure
_handlers = new Dictionary<string, List<IIntegrationEventHandler>>(); _handlers = new Dictionary<string, List<IIntegrationEventHandler>>();
_eventTypes = new List<Type>(); _eventTypes = new List<Type>();
} }
public void Publish(IntegrationEventBase @event) public void Publish(IntegrationEvent @event)
{ {
var eventName = @event.GetType().Name; var eventName = @event.GetType().Name;
var factory = new ConnectionFactory() { HostName = _connectionString }; var factory = new ConnectionFactory() { HostName = _connectionString };
@ -51,7 +51,7 @@ namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure
} }
public void Subscribe<T>(IIntegrationEventHandler<T> handler) where T : IntegrationEventBase public void Subscribe<T>(IIntegrationEventHandler<T> handler) where T : IntegrationEvent
{ {
var eventName = typeof(T).Name; var eventName = typeof(T).Name;
if (_handlers.ContainsKey(eventName)) if (_handlers.ContainsKey(eventName))
@ -72,7 +72,7 @@ namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure
} }
public void Unsubscribe<T>(IIntegrationEventHandler<T> handler) where T : IntegrationEventBase public void Unsubscribe<T>(IIntegrationEventHandler<T> handler) where T : IntegrationEvent
{ {
var eventName = typeof(T).Name; var eventName = typeof(T).Name;
if (_handlers.ContainsKey(eventName) && _handlers[eventName].Contains(handler)) if (_handlers.ContainsKey(eventName) && _handlers[eventName].Contains(handler))

View File

@ -6,8 +6,8 @@ namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure
{ {
public interface IEventBus public interface IEventBus
{ {
void Subscribe<T>(IIntegrationEventHandler<T> handler) where T: IntegrationEventBase; void Subscribe<T>(IIntegrationEventHandler<T> handler) where T: IntegrationEvent;
void Unsubscribe<T>(IIntegrationEventHandler<T> handler) where T : IntegrationEventBase; void Unsubscribe<T>(IIntegrationEventHandler<T> handler) where T : IntegrationEvent;
void Publish(IntegrationEventBase @event); void Publish(IntegrationEvent @event);
} }
} }

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure
{ {
public interface IIntegrationEventHandler<in TIntegrationEvent> : IIntegrationEventHandler public interface IIntegrationEventHandler<in TIntegrationEvent> : IIntegrationEventHandler
where TIntegrationEvent: IntegrationEventBase where TIntegrationEvent: IntegrationEvent
{ {
Task Handle(TIntegrationEvent @event); Task Handle(TIntegrationEvent @event);
} }

View File

@ -5,6 +5,7 @@
<RootNamespace>Microsoft.eShopOnContainers.Services.Common.Infrastructure</RootNamespace> <RootNamespace>Microsoft.eShopOnContainers.Services.Common.Infrastructure</RootNamespace>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="RabbitMQ.Client" Version="4.1.1" /> <PackageReference Include="RabbitMQ.Client" Version="4.1.1" />
</ItemGroup> </ItemGroup>

View File

@ -4,9 +4,9 @@ using System.Text;
namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure
{ {
public class IntegrationEventBase public class IntegrationEvent
{ {
public IntegrationEventBase() public IntegrationEvent()
{ {
Id = Guid.NewGuid(); Id = Guid.NewGuid();
} }