Browse Source

Add Integration Events and Pay Order Command msg handler

pull/809/head
Christian Arenas 7 years ago
parent
commit
2ade7a87e8
8 changed files with 89 additions and 2 deletions
  1. +1
    -1
      docker-compose.vs.debug.yml
  2. +1
    -1
      docker-compose.yml
  3. +19
    -0
      src/Services/Payment/Payment.API/IntegrationCommands/CommandHandlers/PayOrderCommandMsgHandler.cs
  4. +11
    -0
      src/Services/Payment/Payment.API/IntegrationCommands/Commands/PayOrderCommandMsg.cs
  5. +11
    -0
      src/Services/Payment/Payment.API/IntegrationEvents/Events/OrderPaymentFailedIntegrationEvent.cs
  6. +11
    -0
      src/Services/Payment/Payment.API/IntegrationEvents/Events/OrderPaymentSuccededIntegrationEvent.cs
  7. +5
    -0
      src/Services/Payment/Payment.API/Payment.API.csproj
  8. +30
    -0
      src/Services/Payment/Payment.API/Startup.cs

+ 1
- 1
docker-compose.vs.debug.yml View File

@ -107,7 +107,7 @@ services:
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
payment.api:
image: payment.api:dev
image: eshop/payment.api:dev
build:
args:
source: ${DOCKER_BUILD_SOURCE}


+ 1
- 1
docker-compose.yml View File

@ -86,7 +86,7 @@ services:
dockerfile: Dockerfile
payment.api:
image: payment.api
image: eshop/payment.api
build:
context: ./src/Services/Payment/Payment.API
dockerfile: Dockerfile

+ 19
- 0
src/Services/Payment/Payment.API/IntegrationCommands/CommandHandlers/PayOrderCommandMsgHandler.cs View File

@ -0,0 +1,19 @@
namespace Payment.API.IntegrationCommands.CommandHandlers
{
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Payment.API.IntegrationCommands.Commands;
using System.Threading.Tasks;
using System;
public class PayOrderCommandMsgHandler : IIntegrationEventHandler<PayOrderCommandMsg>
{
public PayOrderCommandMsgHandler()
{
}
public async Task Handle(PayOrderCommandMsg @event)
{
throw new NotImplementedException();
}
}
}

+ 11
- 0
src/Services/Payment/Payment.API/IntegrationCommands/Commands/PayOrderCommandMsg.cs View File

@ -0,0 +1,11 @@
namespace Payment.API.IntegrationCommands.Commands
{
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
public class PayOrderCommandMsg : IntegrationEvent
{
public int OrderId { get; }
public PayOrderCommandMsg(int orderId) => OrderId = orderId;
}
}

+ 11
- 0
src/Services/Payment/Payment.API/IntegrationEvents/Events/OrderPaymentFailedIntegrationEvent.cs View File

@ -0,0 +1,11 @@
namespace Payment.API.IntegrationEvents.Events
{
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
public class OrderPaymentFailedIntegrationEvent : IntegrationEvent
{
public int OrderId { get; }
public OrderPaymentFailedIntegrationEvent(int orderId) => OrderId = orderId;
}
}

+ 11
- 0
src/Services/Payment/Payment.API/IntegrationEvents/Events/OrderPaymentSuccededIntegrationEvent.cs View File

@ -0,0 +1,11 @@
namespace Payment.API.IntegrationEvents.Events
{
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
public class OrderPaymentSuccededIntegrationEvent : IntegrationEvent
{
public int OrderId { get; }
public OrderPaymentSuccededIntegrationEvent(int orderId) => OrderId = orderId;
}
}

+ 5
- 0
src/Services/Payment/Payment.API/Payment.API.csproj View File

@ -25,5 +25,10 @@
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusRabbitMQ\EventBusRabbitMQ.csproj" />
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBus\EventBus.csproj" />
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\IntegrationEventLogEF\IntegrationEventLogEF.csproj" />
</ItemGroup>
</Project>

+ 30
- 0
src/Services/Payment/Payment.API/Startup.cs View File

@ -6,6 +6,11 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Payment.API.IntegrationCommands.Commands;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ;
using RabbitMQ.Client;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
namespace Payment.API
{
@ -29,6 +34,21 @@ namespace Payment.API
// Add framework services.
services.AddMvc();
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
{
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
var factory = new ConnectionFactory()
{
HostName = Configuration["EventBusConnection"]
};
return new DefaultRabbitMQPersistentConnection(factory, logger);
});
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
services.AddSwaggerGen();
services.ConfigureSwaggerGen(options =>
{
@ -47,6 +67,8 @@ namespace Payment.API
return new AutofacServiceProvider(container.Build());
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
@ -57,6 +79,14 @@ namespace Payment.API
app.UseSwagger()
.UseSwaggerUi();
ConfigureEventBus(app);
}
private void ConfigureEventBus(IApplicationBuilder app)
{
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
eventBus.Subscribe<PayOrderCommandMsg, IIntegrationEventHandler<PayOrderCommandMsg>>();
}
}
}

Loading…
Cancel
Save