Add Integration Events and Pay Order Command msg handler
This commit is contained in:
parent
82fe859584
commit
2ade7a87e8
@ -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}
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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>
|
||||
|
@ -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…
x
Reference in New Issue
Block a user