Browse Source

ordering.api error integrationevents

features/migration-dotnet3
Erik Pique 5 years ago
parent
commit
216463f847
10 changed files with 39 additions and 24 deletions
  1. +2
    -5
      src/BuildingBlocks/EventBus/IntegrationEventLogEF/IntegrationEventLogEntry.cs
  2. +11
    -11
      src/BuildingBlocks/EventBus/IntegrationEventLogEF/Services/IntegrationEventLogService.cs
  3. +11
    -1
      src/Services/Basket/Basket.API/Controllers/BasketController.cs
  4. +1
    -1
      src/Services/Catalog/Catalog.API/Startup.cs
  5. +0
    -2
      src/Services/Ordering/Ordering.API/Application/Behaviors/TransactionBehaviour.cs
  6. +1
    -1
      src/Services/Ordering/Ordering.API/Startup.cs
  7. +1
    -0
      src/Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj
  8. +5
    -1
      src/Services/Ordering/Ordering.SignalrHub/Startup.cs
  9. +1
    -1
      src/Services/Webhooks/Webhooks.API/Startup.cs
  10. +6
    -1
      src/Web/WebMVC/Services/BasketService.cs

+ 2
- 5
src/BuildingBlocks/EventBus/IntegrationEventLogEF/IntegrationEventLogEntry.cs View File

@ -14,7 +14,7 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF
public class IntegrationEventLogEntry
{
private IntegrationEventLogEntry() { }
public IntegrationEventLogEntry(IntegrationEvent @event, Guid transactionId, ILogger<IntegrationEventLogService> logger)
public IntegrationEventLogEntry(IntegrationEvent @event, Guid transactionId)
{
EventId = @event.Id;
CreationTime = @event.CreationDate;
@ -23,7 +23,6 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF
State = EventStateEnum.NotPublished;
TimesSent = 0;
TransactionId = transactionId.ToString();
}
public Guid EventId { get; private set; }
public string EventTypeName { get; private set; }
@ -37,10 +36,8 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF
public string Content { get; private set; }
public string TransactionId { get; private set; }
public IntegrationEventLogEntry DeserializeJsonContent(Type type, ILogger<IntegrationEventLogService> logger)
public IntegrationEventLogEntry DeserializeJsonContent(Type type)
{
logger.LogInformation("----- DeserializeJsonContent {Content} {Type}", Content, type);
IntegrationEvent = JsonConvert.DeserializeObject(Content, type) as IntegrationEvent;
return this;
}


+ 11
- 11
src/BuildingBlocks/EventBus/IntegrationEventLogEF/Services/IntegrationEventLogService.cs View File

@ -18,13 +18,11 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Servi
public class IntegrationEventLogService : IIntegrationEventLogService
{
private readonly IntegrationEventLogContext _integrationEventLogContext;
private readonly ILogger<IntegrationEventLogService> _logger;
private readonly DbConnection _dbConnection;
private readonly List<Type> _eventTypes;
public IntegrationEventLogService(DbConnection dbConnection, ILogger<IntegrationEventLogService> logger)
public IntegrationEventLogService(DbConnection dbConnection)
{
_logger =logger;
_dbConnection = dbConnection ?? throw new ArgumentNullException(nameof(dbConnection));
_integrationEventLogContext = new IntegrationEventLogContext(
new DbContextOptionsBuilder<IntegrationEventLogContext>()
@ -40,22 +38,24 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Servi
public async Task<IEnumerable<IntegrationEventLogEntry>> RetrieveEventLogsPendingToPublishAsync(Guid transactionId)
{
_logger.LogInformation("----- RetrieveEventLogsPendingToPublishAsync {TransactionId}", transactionId);
var tid = transactionId.ToString();
return await _integrationEventLogContext.IntegrationEventLogs
.Where(e => e.TransactionId == tid && e.State == EventStateEnum.NotPublished)
.OrderBy(o => o.CreationTime)
.Select(e => e.DeserializeJsonContent(_eventTypes.Find(t=> t.Name == e.EventTypeShortName), _logger))
.ToListAsync();
var result = await _integrationEventLogContext.IntegrationEventLogs
.Where(e => e.TransactionId == tid && e.State == EventStateEnum.NotPublished).ToListAsync();
if(result != null && result.Any()){
return result.OrderBy(o => o.CreationTime)
.Select(e => e.DeserializeJsonContent(_eventTypes.Find(t=> t.Name == e.EventTypeShortName)));
}
return new List<IntegrationEventLogEntry>();
}
public Task SaveEventAsync(IntegrationEvent @event, IDbContextTransaction transaction)
{
if (transaction == null) throw new ArgumentNullException(nameof(transaction));
var eventLogEntry = new IntegrationEventLogEntry(@event, transaction.TransactionId, _logger);
var eventLogEntry = new IntegrationEventLogEntry(@event, transaction.TransactionId);
_integrationEventLogContext.Database.UseTransaction(transaction.GetDbTransaction());
_integrationEventLogContext.IntegrationEventLogs.Add(eventLogEntry);


+ 11
- 1
src/Services/Basket/Basket.API/Controllers/BasketController.cs View File

@ -7,7 +7,9 @@ using Microsoft.eShopOnContainers.Services.Basket.API.Model;
using Microsoft.eShopOnContainers.Services.Basket.API.Services;
using Microsoft.Extensions.Logging;
using System;
using System.Linq;
using System.Net;
using System.Security.Claims;
using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
@ -61,6 +63,8 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
basketCheckout.RequestId = (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty) ?
guid : basketCheckout.RequestId;
_logger.LogInformation("----- CheckoutAsync userId: {userId} ", userId);
var basket = await _repository.GetBasketAsync(userId);
if (basket == null)
@ -68,7 +72,13 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
return BadRequest();
}
var userName = User.FindFirst(x => x.Type == "unique_name").Value;
_logger.LogInformation("----- CheckoutAsync basket: {@basket} ", basket);
_logger.LogInformation("----- CheckoutAsync user identity: {User} ", string.Join(':', ((ClaimsIdentity)User.Identity).Claims.Select(c => c.Type + " " + c.Value)));
var userName = User.FindFirst(x => x.Type == ClaimTypes.Name).Value;
_logger.LogInformation("----- CheckoutAsync userName: {@userName} ", userName);
var eventMessage = new UserCheckoutAcceptedIntegrationEvent(userId, userName, basketCheckout.City, basketCheckout.Street,
basketCheckout.State, basketCheckout.Country, basketCheckout.ZipCode, basketCheckout.CardNumber, basketCheckout.CardHolderName,


+ 1
- 1
src/Services/Catalog/Catalog.API/Startup.cs View File

@ -277,7 +277,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
public static IServiceCollection AddIntegrationServices(this IServiceCollection services, IConfiguration configuration)
{
services.AddTransient<Func<DbConnection, IIntegrationEventLogService>>(
sp => (DbConnection c) => new IntegrationEventLogService(c, sp.GetService<ILogger<IntegrationEventLogService>>()));
sp => (DbConnection c) => new IntegrationEventLogService(c));
services.AddTransient<ICatalogIntegrationEventService, CatalogIntegrationEventService>();


+ 0
- 2
src/Services/Ordering/Ordering.API/Application/Behaviors/TransactionBehaviour.cs View File

@ -56,8 +56,6 @@ namespace Ordering.API.Application.Behaviors
await _dbContext.CommitTransactionAsync(transaction);
transactionId = transaction.TransactionId;
_logger.LogInformation("----- End transaction {TransactionId} for {CommandName}", transaction.TransactionId, typeName);
}
await _orderingIntegrationEventService.PublishEventsThroughEventBusAsync(transactionId);


+ 1
- 1
src/Services/Ordering/Ordering.API/Startup.cs View File

@ -273,7 +273,7 @@
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddTransient<IIdentityService, IdentityService>();
services.AddTransient<Func<DbConnection, IIntegrationEventLogService>>(
sp => (DbConnection c) => new IntegrationEventLogService(c, sp.GetService<ILogger<IntegrationEventLogService>>()));
sp => (DbConnection c) => new IntegrationEventLogService(c));
services.AddTransient<IOrderingIntegrationEventService, OrderingIntegrationEventService>();


+ 1
- 0
src/Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj View File

@ -27,6 +27,7 @@
<PackageReference Include="Microsoft.AspNetCore.SignalR.Redis" Version="$(Microsoft_AspNetCore_SignalR_Redis)" />
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="$(Microsoft_Extensions_Logging_AzureAppServices)" />
<PackageReference Include="Serilog.AspNetCore" Version="$(Serilog_AspNetCore)" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="$(Microsoft_AspNetCore_App)" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="$(Serilog_Enrichers_Environment)" />
<PackageReference Include="Serilog.Settings.Configuration" Version="$(Serilog_Settings_Configuration)" />
<PackageReference Include="Serilog.Sinks.Console" Version="$(Serilog_Sinks_Console)" />


+ 5
- 1
src/Services/Ordering/Ordering.SignalrHub/Startup.cs View File

@ -109,7 +109,7 @@ namespace Ordering.SignalrHub
RegisterEventBus(services);
services.AddOptions();
//configure autofac
var container = new ContainerBuilder();
container.RegisterModule(new ApplicationModule());
@ -136,6 +136,10 @@ namespace Ordering.SignalrHub
app.UseCors("CorsPolicy");
app.UseRouting();
//app.UseAuthorization();
app.UseAutentication();
app.UseEndpoints(endpoints =>
{
endpoints.MapHealthChecks("/hc", new HealthCheckOptions()


+ 1
- 1
src/Services/Webhooks/Webhooks.API/Startup.cs View File

@ -291,7 +291,7 @@ namespace Webhooks.API
public static IServiceCollection AddIntegrationServices(this IServiceCollection services, IConfiguration configuration)
{
services.AddTransient<Func<DbConnection, IIntegrationEventLogService>>(
sp => (DbConnection c) => new IntegrationEventLogService(c, sp.GetService<ILogger<IntegrationEventLogService>>()));
sp => (DbConnection c) => new IntegrationEventLogService(c));
if (configuration.GetValue<bool>("AzureServiceBusEnabled"))
{


+ 6
- 1
src/Web/WebMVC/Services/BasketService.cs View File

@ -1,4 +1,5 @@
using Microsoft.eShopOnContainers.WebMVC.ViewModels;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using System.Collections.Generic;
@ -14,15 +15,17 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services
{
private readonly IOptions<AppSettings> _settings;
private readonly HttpClient _apiClient;
private readonly ILogger<BasketService> _logger;
private readonly string _basketByPassUrl;
private readonly string _purchaseUrl;
private readonly string _bffUrl;
public BasketService(HttpClient httpClient, IOptions<AppSettings> settings)
public BasketService(HttpClient httpClient, IOptions<AppSettings> settings, ILogger<BasketService> logger)
{
_apiClient = httpClient;
_settings = settings;
_logger =logger;
_basketByPassUrl = $"{_settings.Value.PurchaseUrl}/api/v1/b/basket";
_purchaseUrl = $"{_settings.Value.PurchaseUrl}/api/v1";
@ -57,6 +60,8 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services
var uri = API.Basket.CheckoutBasket(_basketByPassUrl);
var basketContent = new StringContent(JsonConvert.SerializeObject(basket), System.Text.Encoding.UTF8, "application/json");
_logger.LogInformation("Uri chechout {uri}", uri);
var response = await _apiClient.PostAsync(uri, basketContent);
response.EnsureSuccessStatusCode();


Loading…
Cancel
Save