Larger Refactoring of IntegrationEvents
This commit is contained in:
parent
e41ce96f81
commit
8423c8bb63
@ -12,6 +12,10 @@
|
||||
<DockerComposeProjectPath>..\..\..\..\docker-compose.dcproj</DockerComposeProjectPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="IntegrationEvents\Events\ProductPriceChangedEvent.cs.txt" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="web.config">
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
@ -23,16 +27,16 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Threading" Version="4.3.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
|
||||
<PackageReference Include="StackExchange.Redis" Version="1.1.608" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
|
||||
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="1.0.1-rc3" />
|
||||
|
@ -6,17 +6,17 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
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;
|
||||
public ProductPriceChangedHandler(IBasketRepository repository)
|
||||
public ProductPriceChangedEventHandler(IBasketRepository repository)
|
||||
{
|
||||
_repository = repository;
|
||||
}
|
||||
|
||||
public async Task Handle(ProductPriceChanged @event)
|
||||
public async Task Handle(ProductPriceChangedEvent @event)
|
||||
{
|
||||
var userIds = await _repository.GetUsers();
|
||||
foreach (var id in userIds)
|
@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
// To implement ProductPriceChangedEvent.cs here
|
@ -15,7 +15,7 @@ using Swashbuckle.Swagger.Model;
|
||||
using Microsoft.eShopOnContainers.Services.Basket.API.Auth.Server;
|
||||
using Microsoft.eShopOnContainers.Services.Common.Infrastructure;
|
||||
using Microsoft.eShopOnContainers.Services.Common.Infrastructure.Catalog;
|
||||
using Basket.API.Events;
|
||||
using Basket.API.IntegrationEvents.EventHandling;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Basket.API
|
||||
{
|
||||
@ -79,7 +79,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
||||
});
|
||||
|
||||
services.AddTransient<IBasketRepository, RedisBasketRepository>();
|
||||
services.AddTransient<IIntegrationEventHandler<ProductPriceChanged>, ProductPriceChangedHandler>();
|
||||
services.AddTransient<IIntegrationEventHandler<ProductPriceChangedEvent>, ProductPriceChangedEventHandler>();
|
||||
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
var configuration = serviceProvider.GetRequiredService<IOptionsSnapshot<BasketSettings>>().Value;
|
||||
@ -87,8 +87,8 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
||||
services.AddSingleton<IEventBus>(eventBus);
|
||||
|
||||
|
||||
var catalogPriceHandler = serviceProvider.GetService<IIntegrationEventHandler<ProductPriceChanged>>();
|
||||
eventBus.Subscribe<ProductPriceChanged>(catalogPriceHandler);
|
||||
var catalogPriceHandler = serviceProvider.GetService<IIntegrationEventHandler<ProductPriceChangedEvent>>();
|
||||
eventBus.Subscribe<ProductPriceChangedEvent>(catalogPriceHandler);
|
||||
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,8 @@
|
||||
<Content Include="Pics\**\*;">
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
<Compile Include="IntegrationEvents\EventHandling\AnyFutureIntegrationEventHandler.cs.txt" />
|
||||
<Compile Include="IntegrationEvents\Events\ProductPriceChangedEvent.cs.txt" />
|
||||
<Content Update="web.config;">
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
@ -28,23 +30,24 @@
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.Abstractions" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.Abstractions" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="1.1.1" />
|
||||
<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="Swashbuckle" Version="6.0.0-beta902" />
|
||||
</ItemGroup>
|
||||
|
@ -149,7 +149,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
_context.CatalogItems.Update(item);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
var @event = new ProductPriceChanged(item.Id, item.Price, oldPrice);
|
||||
var @event = new ProductPriceChangedEvent(item.Id, item.Price, oldPrice);
|
||||
await ProcessEventAsync(@event);
|
||||
}
|
||||
|
||||
@ -166,14 +166,14 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
return items;
|
||||
}
|
||||
|
||||
private async Task ProcessEventAsync(IntegrationEventBase @event)
|
||||
private async Task ProcessEventAsync(IntegrationEvent @event)
|
||||
{
|
||||
_eventBus.Publish(@event);
|
||||
var eventData = new IntegrationEvent(@event);
|
||||
eventData.TimesSent++;
|
||||
eventData.State = EventStateEnum.Sent;
|
||||
var eventLogEntry = new IntegrationEventLogEntry(@event);
|
||||
eventLogEntry.TimesSent++;
|
||||
eventLogEntry.State = EventStateEnum.Published;
|
||||
|
||||
_context.IntegrationEvents.Add(eventData);
|
||||
_context.IntegrationEventLog.Add(eventLogEntry);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
}
|
||||
|
@ -13,14 +13,14 @@
|
||||
public DbSet<CatalogItem> CatalogItems { get; set; }
|
||||
public DbSet<CatalogBrand> CatalogBrands { 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)
|
||||
{
|
||||
builder.Entity<CatalogBrand>(ConfigureCatalogBrand);
|
||||
builder.Entity<CatalogType>(ConfigureCatalogType);
|
||||
builder.Entity<CatalogItem>(ConfigureCatalogItem);
|
||||
builder.Entity<IntegrationEvent>(ConfigureIntegrationEvent);
|
||||
builder.Entity<IntegrationEventLogEntry>(ConfigureIntegrationEventLogEntry);
|
||||
}
|
||||
|
||||
void ConfigureCatalogItem(EntityTypeBuilder<CatalogItem> builder)
|
||||
@ -80,9 +80,9 @@
|
||||
.HasMaxLength(100);
|
||||
}
|
||||
|
||||
void ConfigureIntegrationEvent(EntityTypeBuilder<IntegrationEvent> builder)
|
||||
void ConfigureIntegrationEventLogEntry(EntityTypeBuilder<IntegrationEventLogEntry> builder)
|
||||
{
|
||||
builder.ToTable("IntegrationEvent");
|
||||
builder.ToTable("IntegrationEventLog");
|
||||
|
||||
builder.HasKey(e => e.EventId);
|
||||
|
||||
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@ namespace Catalog.API.Infrastructure.Migrations
|
||||
protected override void BuildModel(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_hilo", "'catalog_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");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Common.Infrastructure.Data.IntegrationEvent", b =>
|
||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Common.Infrastructure.Data.IntegrationEventLogEntry", b =>
|
||||
{
|
||||
b.Property<Guid>("EventId")
|
||||
.ValueGeneratedOnAdd();
|
||||
@ -93,8 +93,7 @@ namespace Catalog.API.Infrastructure.Migrations
|
||||
b.Property<DateTime>("CreationTime");
|
||||
|
||||
b.Property<string>("EventTypeName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200);
|
||||
.IsRequired();
|
||||
|
||||
b.Property<int>("State");
|
||||
|
||||
@ -102,7 +101,7 @@ namespace Catalog.API.Infrastructure.Migrations
|
||||
|
||||
b.HasKey("EventId");
|
||||
|
||||
b.ToTable("IntegrationEvent");
|
||||
b.ToTable("IntegrationEventLog");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogItem", b =>
|
||||
|
@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
// To implement ProductPriceChangedEvent.cs here
|
@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
// To implement any future integration event handler here
|
@ -4,7 +4,10 @@ using System.Text;
|
||||
|
||||
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; }
|
||||
|
||||
@ -12,11 +15,11 @@ namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure.Catalog
|
||||
|
||||
public decimal OldPrice { get; private set; }
|
||||
|
||||
public ProductPriceChanged(int productId, decimal newPrice, decimal oldPrice)
|
||||
public ProductPriceChangedEvent(int productId, decimal newPrice, decimal oldPrice)
|
||||
{
|
||||
ProductId = productId;
|
||||
NewPrice = newPrice;
|
||||
OldPrice = oldPrice;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6,8 +6,8 @@ namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure
|
||||
{
|
||||
public enum EventStateEnum
|
||||
{
|
||||
NotSend = 0,
|
||||
Sent = 1,
|
||||
SendingFailed = 2
|
||||
NotPublished = 0,
|
||||
Published = 1,
|
||||
PublishedFailed = 2
|
||||
}
|
||||
}
|
||||
|
@ -5,15 +5,15 @@ using Newtonsoft.Json;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure.Data
|
||||
{
|
||||
public class IntegrationEvent
|
||||
public class IntegrationEventLogEntry
|
||||
{
|
||||
public IntegrationEvent(IntegrationEventBase @event)
|
||||
public IntegrationEventLogEntry(IntegrationEvent @event)
|
||||
{
|
||||
EventId = @event.Id;
|
||||
CreationTime = DateTime.UtcNow;
|
||||
EventTypeName = @event.GetType().FullName;
|
||||
Content = JsonConvert.SerializeObject(@event);
|
||||
State = EventStateEnum.NotSend;
|
||||
State = EventStateEnum.NotPublished;
|
||||
TimesSent = 0;
|
||||
}
|
||||
public Guid EventId { get; private set; }
|
@ -30,7 +30,7 @@ namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure
|
||||
_handlers = new Dictionary<string, List<IIntegrationEventHandler>>();
|
||||
_eventTypes = new List<Type>();
|
||||
}
|
||||
public void Publish(IntegrationEventBase @event)
|
||||
public void Publish(IntegrationEvent @event)
|
||||
{
|
||||
var eventName = @event.GetType().Name;
|
||||
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;
|
||||
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;
|
||||
if (_handlers.ContainsKey(eventName) && _handlers[eventName].Contains(handler))
|
||||
|
@ -6,8 +6,8 @@ namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure
|
||||
{
|
||||
public interface IEventBus
|
||||
{
|
||||
void Subscribe<T>(IIntegrationEventHandler<T> handler) where T: IntegrationEventBase;
|
||||
void Unsubscribe<T>(IIntegrationEventHandler<T> handler) where T : IntegrationEventBase;
|
||||
void Publish(IntegrationEventBase @event);
|
||||
void Subscribe<T>(IIntegrationEventHandler<T> handler) where T: IntegrationEvent;
|
||||
void Unsubscribe<T>(IIntegrationEventHandler<T> handler) where T : IntegrationEvent;
|
||||
void Publish(IntegrationEvent @event);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure
|
||||
{
|
||||
public interface IIntegrationEventHandler<in TIntegrationEvent> : IIntegrationEventHandler
|
||||
where TIntegrationEvent: IntegrationEventBase
|
||||
where TIntegrationEvent: IntegrationEvent
|
||||
{
|
||||
Task Handle(TIntegrationEvent @event);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
<RootNamespace>Microsoft.eShopOnContainers.Services.Common.Infrastructure</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
|
||||
<PackageReference Include="RabbitMQ.Client" Version="4.1.1" />
|
||||
</ItemGroup>
|
||||
|
@ -4,9 +4,9 @@ using System.Text;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure
|
||||
{
|
||||
public class IntegrationEventBase
|
||||
public class IntegrationEvent
|
||||
{
|
||||
public IntegrationEventBase()
|
||||
public IntegrationEvent()
|
||||
{
|
||||
Id = Guid.NewGuid();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user