Browse Source

More stuff

pull/1240/head
espent1004 5 years ago
parent
commit
2be714234b
11 changed files with 141 additions and 14 deletions
  1. +5
    -0
      docker-compose.override.yml
  2. +11
    -2
      src/BuildingBlocks/EventBus/EventBus/Abstractions/AbstractIntegrationEventHandler.cs
  3. +11
    -0
      src/BuildingBlocks/EventBus/EventBus/Events/IntegrationEvent.cs
  4. +4
    -4
      src/BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.cs
  5. +3
    -1
      src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/UserCheckoutAcceptedIntegrationEventHandler.cs
  6. +46
    -0
      src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/CustomisationEventHandler.cs
  7. +14
    -0
      src/Services/TenantCustomisations/TenantACustomisations/Services/IValidationService.cs
  8. +17
    -0
      src/Services/TenantCustomisations/TenantACustomisations/Services/ValidationService.cs
  9. +4
    -1
      src/Services/TenantCustomisations/TenantACustomisations/Startup.cs
  10. +1
    -1
      src/Services/TenantCustomisations/TenantACustomisations/TenantACustomisations.csproj
  11. +25
    -5
      src/Services/TenantCustomisations/TenantACustomisations/appsettings.json

+ 5
- 0
docker-compose.override.yml View File

@ -63,6 +63,11 @@ services:
- "5115:80" - "5115:80"
tenantacustomisation: tenantacustomisation:
environment:
- EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq}
- EventBusUserName=${ESHOP_SERVICE_BUS_USERNAME}
- EventBusPassword=${ESHOP_SERVICE_BUS_PASSWORD}
- AzureServiceBusEnabled=False
ports: ports:
- "5116:80" - "5116:80"


+ 11
- 2
src/BuildingBlocks/EventBus/EventBus/Abstractions/AbstractIntegrationEventHandler.cs View File

@ -13,9 +13,19 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
{ {
private static String url = @"http://tenantmanager/"; private static String url = @"http://tenantmanager/";
private readonly IEventBus _eventBus; private readonly IEventBus _eventBus;
//private readonly ILogger<AbstractIntegrationEventHandler<IIntegrationEvent>> _logger;
protected AbstractIntegrationEventHandler(IEventBus eventBus)
{
_eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus));
}
public async Task<bool> CheckIfCustomised(IntegrationEvent @event) public async Task<bool> CheckIfCustomised(IntegrationEvent @event)
{ {
if (!@event.CheckForCustomisation)
{
return false;
}
Boolean result = Get(@event); Boolean result = Get(@event);
if (result) if (result)
{ {
@ -23,7 +33,6 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
try try
{ {
//_logger.LogInformation("----- Publishing integration event: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", eventMessage.Id, Program.AppName, eventMessage); //_logger.LogInformation("----- Publishing integration event: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", eventMessage.Id, Program.AppName, eventMessage);
_eventBus.Publish(customisationEvent); _eventBus.Publish(customisationEvent);
} }
catch (Exception ex) catch (Exception ex)
@ -58,7 +67,7 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
} }
} }
return false;
return true;
} }
} }


+ 11
- 0
src/BuildingBlocks/EventBus/EventBus/Events/IntegrationEvent.cs View File

@ -9,6 +9,14 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events
{ {
Id = Guid.NewGuid(); Id = Guid.NewGuid();
CreationDate = DateTime.UtcNow; CreationDate = DateTime.UtcNow;
CheckForCustomisation = true;
}
public IntegrationEvent(Boolean checkForCustomisation)
{
Id = Guid.NewGuid();
CreationDate = DateTime.UtcNow;
CheckForCustomisation = checkForCustomisation;
} }
[JsonConstructor] [JsonConstructor]
@ -23,5 +31,8 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events
[JsonProperty] [JsonProperty]
public DateTime CreationDate { get; private set; } public DateTime CreationDate { get; private set; }
[JsonProperty]
public Boolean CheckForCustomisation { get; set; }
} }
} }

+ 4
- 4
src/BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.cs View File

@ -82,12 +82,12 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
var eventName = @event.GetType().Name; var eventName = @event.GetType().Name;
_logger.LogTrace("Creating RabbitMQ channel to publish event: {EventId} ({EventName})", @event.Id, eventName);
_logger.LogWarning("Creating RabbitMQ channel to publish event: {EventId} ({EventName})", @event.Id, eventName);
using (var channel = _persistentConnection.CreateModel()) using (var channel = _persistentConnection.CreateModel())
{ {
_logger.LogTrace("Declaring RabbitMQ exchange to publish event: {EventId}", @event.Id);
_logger.LogWarning("Declaring RabbitMQ exchange to publish event: {EventId}", @event.Id);
channel.ExchangeDeclare(exchange: BROKER_NAME, type: "direct"); channel.ExchangeDeclare(exchange: BROKER_NAME, type: "direct");
@ -99,7 +99,7 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
var properties = channel.CreateBasicProperties(); var properties = channel.CreateBasicProperties();
properties.DeliveryMode = 2; // persistent properties.DeliveryMode = 2; // persistent
_logger.LogTrace("Publishing event to RabbitMQ: {EventId}", @event.Id);
_logger.LogWarning("Publishing event to RabbitMQ: {EventId}", @event.Id);
channel.BasicPublish( channel.BasicPublish(
exchange: BROKER_NAME, exchange: BROKER_NAME,
@ -260,7 +260,7 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
private async Task ProcessEvent(string eventName, string message) private async Task ProcessEvent(string eventName, string message)
{ {
_logger.LogTrace("Processing RabbitMQ event: {EventName}", eventName);
_logger.LogWarning("Processing RabbitMQ event: {EventName}", eventName);
if (_subsManager.HasSubscriptionsForEvent(eventName)) if (_subsManager.HasSubscriptionsForEvent(eventName))
{ {


+ 3
- 1
src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/UserCheckoutAcceptedIntegrationEventHandler.cs View File

@ -15,14 +15,16 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
public class UserCheckoutAcceptedIntegrationEventHandler : AbstractIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>, IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent> public class UserCheckoutAcceptedIntegrationEventHandler : AbstractIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>, IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>
{ {
private readonly IMediator _mediator; private readonly IMediator _mediator;
private readonly IEventBus _eventBus;
private readonly ILogger<UserCheckoutAcceptedIntegrationEventHandler> _logger; private readonly ILogger<UserCheckoutAcceptedIntegrationEventHandler> _logger;
public UserCheckoutAcceptedIntegrationEventHandler( public UserCheckoutAcceptedIntegrationEventHandler(
IMediator mediator, IMediator mediator,
ILogger<UserCheckoutAcceptedIntegrationEventHandler> logger)
ILogger<UserCheckoutAcceptedIntegrationEventHandler> logger, IEventBus eventBus) : base(eventBus)
{ {
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); _mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); _logger = logger ?? throw new ArgumentNullException(nameof(logger));
_eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus));
} }
/// <summary> /// <summary>


+ 46
- 0
src/Services/TenantCustomisations/TenantACustomisations/IntegrationEvents/EventHandling/CustomisationEventHandler.cs View File

@ -0,0 +1,46 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.IntegrationEvents.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TenantACustomisations.Services;
namespace TenantACustomisations.IntegrationEvents.EventHandling
{
public class CustomisationEventHandler : IIntegrationEventHandler<CustomisationEvent>
{
private readonly ILogger<CustomisationEventHandler> _logger;
private readonly IEventBus _eventBus;
private readonly IValidationService validationService;
public CustomisationEventHandler(ILogger<CustomisationEventHandler> logger, IEventBus eventBus)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus));
validationService = new ValidationService();
}
public async Task Handle(CustomisationEvent @event)
{
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
IntegrationEvent integrationEvent = @event.@event;
switch (integrationEvent.GetType().Name)
{
case "UserCheckoutAcceptedIntegrationEvent":
if (validationService.Validate((UserCheckoutAcceptedIntegrationEvent)integrationEvent))
{
integrationEvent.CheckForCustomisation = false;
_eventBus.Publish(integrationEvent);
}
break;
default:
break;
}
}
}
}

+ 14
- 0
src/Services/TenantCustomisations/TenantACustomisations/Services/IValidationService.cs View File

@ -0,0 +1,14 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
using Ordering.API.Application.IntegrationEvents.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TenantACustomisations.Services
{
interface IValidationService
{
Boolean Validate(UserCheckoutAcceptedIntegrationEvent @event);
}
}

+ 17
- 0
src/Services/TenantCustomisations/TenantACustomisations/Services/ValidationService.cs View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
using Ordering.API.Application.IntegrationEvents.Events;
namespace TenantACustomisations.Services
{
public class ValidationService : IValidationService
{
public bool Validate(UserCheckoutAcceptedIntegrationEvent @event)
{
return @event.State == "Oslo";
}
}
}

+ 4
- 1
src/Services/TenantCustomisations/TenantACustomisations/Startup.cs View File

@ -33,6 +33,8 @@
using Infrastructure.AutofacModules; using Infrastructure.AutofacModules;
using Microsoft.eShopOnContainers.Services.TenantACustomisations.Infrastructure.Filters; using Microsoft.eShopOnContainers.Services.TenantACustomisations.Infrastructure.Filters;
using global::TenantACustomisations.Infrastructure.Filters; using global::TenantACustomisations.Infrastructure.Filters;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
using global::TenantACustomisations.IntegrationEvents.EventHandling;
public class Startup public class Startup
{ {
@ -112,7 +114,7 @@
{ {
var eventBus = app.ApplicationServices.GetRequiredService<BuildingBlocks.EventBus.Abstractions.IEventBus>(); var eventBus = app.ApplicationServices.GetRequiredService<BuildingBlocks.EventBus.Abstractions.IEventBus>();
//eventBus.Subscribe<UserCheckoutAcceptedIntegrationEvent, IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>();
eventBus.Subscribe<CustomisationEvent, CustomisationEventHandler>();
} }
protected virtual void ConfigureAuth(IApplicationBuilder app) protected virtual void ConfigureAuth(IApplicationBuilder app)
@ -385,6 +387,7 @@
} }
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>(); services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
services.AddTransient<CustomisationEventHandler>();
return services; return services;
} }


+ 1
- 1
src/Services/TenantCustomisations/TenantACustomisations/TenantACustomisations.csproj View File

@ -44,7 +44,6 @@
<ItemGroup> <ItemGroup>
<Folder Include="IntegrationEvents\Events\" /> <Folder Include="IntegrationEvents\Events\" />
<Folder Include="IntegrationEvents\EventHandling\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -52,6 +51,7 @@
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusServiceBus\EventBusServiceBus.csproj" /> <ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusServiceBus\EventBusServiceBus.csproj" />
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBus\EventBus.csproj" /> <ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBus\EventBus.csproj" />
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\IntegrationEventLogEF\IntegrationEventLogEF.csproj" /> <ProjectReference Include="..\..\..\BuildingBlocks\EventBus\IntegrationEventLogEF\IntegrationEventLogEF.csproj" />
<ProjectReference Include="..\..\Ordering\Ordering.API\Ordering.API.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>


+ 25
- 5
src/Services/TenantCustomisations/TenantACustomisations/appsettings.json View File

@ -1,8 +1,28 @@
{ {
"Logging": {
"LogLevel": {
"Default": "Warning"
"Serilog": {
"SeqServerUrl": null,
"LogstashgUrl": null,
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"Microsoft.eShopOnContainers": "Information",
"System": "Warning"
}
} }
}, },
"AllowedHosts": "*"
}
"IdentityUrl": "http://localhost:5105",
"ConnectionString": "127.0.0.1",
"AzureServiceBusEnabled": false,
"SubscriptionClientName": "TenantACustomisation",
"ApplicationInsights": {
"InstrumentationKey": ""
},
"EventBusRetryCount": 5,
"UseVault": false,
"Vault": {
"Name": "eshop",
"ClientId": "your-clien-id",
"ClientSecret": "your-client-secret"
}
}

Loading…
Cancel
Save