Skip to content

Commit 2ade7a8

Browse files
committed
Add Integration Events and Pay Order Command msg handler
1 parent 82fe859 commit 2ade7a8

8 files changed

Lines changed: 89 additions & 2 deletions

File tree

docker-compose.vs.debug.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ services:
107107
- "com.microsoft.visualstudio.targetoperatingsystem=linux"
108108

109109
payment.api:
110-
image: payment.api:dev
110+
image: eshop/payment.api:dev
111111
build:
112112
args:
113113
source: ${DOCKER_BUILD_SOURCE}

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ services:
8686
dockerfile: Dockerfile
8787

8888
payment.api:
89-
image: payment.api
89+
image: eshop/payment.api
9090
build:
9191
context: ./src/Services/Payment/Payment.API
9292
dockerfile: Dockerfile
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace Payment.API.IntegrationCommands.CommandHandlers
2+
{
3+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
4+
using Payment.API.IntegrationCommands.Commands;
5+
using System.Threading.Tasks;
6+
using System;
7+
8+
public class PayOrderCommandMsgHandler : IIntegrationEventHandler<PayOrderCommandMsg>
9+
{
10+
public PayOrderCommandMsgHandler()
11+
{
12+
}
13+
14+
public async Task Handle(PayOrderCommandMsg @event)
15+
{
16+
throw new NotImplementedException();
17+
}
18+
}
19+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Payment.API.IntegrationCommands.Commands
2+
{
3+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
4+
5+
public class PayOrderCommandMsg : IntegrationEvent
6+
{
7+
public int OrderId { get; }
8+
9+
public PayOrderCommandMsg(int orderId) => OrderId = orderId;
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Payment.API.IntegrationEvents.Events
2+
{
3+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
4+
5+
public class OrderPaymentFailedIntegrationEvent : IntegrationEvent
6+
{
7+
public int OrderId { get; }
8+
9+
public OrderPaymentFailedIntegrationEvent(int orderId) => OrderId = orderId;
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Payment.API.IntegrationEvents.Events
2+
{
3+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
4+
5+
public class OrderPaymentSuccededIntegrationEvent : IntegrationEvent
6+
{
7+
public int OrderId { get; }
8+
9+
public OrderPaymentSuccededIntegrationEvent(int orderId) => OrderId = orderId;
10+
}
11+
}

src/Services/Payment/Payment.API/Payment.API.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,10 @@
2525
<ItemGroup>
2626
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" />
2727
</ItemGroup>
28+
<ItemGroup>
29+
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusRabbitMQ\EventBusRabbitMQ.csproj" />
30+
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBus\EventBus.csproj" />
31+
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\IntegrationEventLogEF\IntegrationEventLogEF.csproj" />
32+
</ItemGroup>
2833

2934
</Project>

src/Services/Payment/Payment.API/Startup.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
using Microsoft.Extensions.DependencyInjection;
77
using Microsoft.Extensions.Logging;
88
using System;
9+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
10+
using Payment.API.IntegrationCommands.Commands;
11+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ;
12+
using RabbitMQ.Client;
13+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
914

1015
namespace Payment.API
1116
{
@@ -29,6 +34,21 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
2934
// Add framework services.
3035
services.AddMvc();
3136

37+
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
38+
{
39+
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
40+
41+
var factory = new ConnectionFactory()
42+
{
43+
HostName = Configuration["EventBusConnection"]
44+
};
45+
46+
return new DefaultRabbitMQPersistentConnection(factory, logger);
47+
});
48+
49+
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
50+
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
51+
3252
services.AddSwaggerGen();
3353
services.ConfigureSwaggerGen(options =>
3454
{
@@ -47,6 +67,8 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
4767
return new AutofacServiceProvider(container.Build());
4868
}
4969

70+
71+
5072
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
5173
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
5274
{
@@ -57,6 +79,14 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
5779

5880
app.UseSwagger()
5981
.UseSwaggerUi();
82+
83+
ConfigureEventBus(app);
84+
}
85+
86+
private void ConfigureEventBus(IApplicationBuilder app)
87+
{
88+
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
89+
eventBus.Subscribe<PayOrderCommandMsg, IIntegrationEventHandler<PayOrderCommandMsg>>();
6090
}
6191
}
6292
}

0 commit comments

Comments
 (0)