Skip to content

Commit

Permalink
Merge pull request #11 from ofmaska/master
Browse files Browse the repository at this point in the history
Handle PaymentCompletedEvent #6
  • Loading branch information
starkmsu authored May 4, 2020
2 parents b7ae1f6 + 422d275 commit fd9a586
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<PackageReference Include="AutoMapper" Version="9.0.0" />
<PackageReference Include="Lykke.RabbitMqBroker" Version="7.13.1" />
<PackageReference Include="MAVN.Service.PaymentManagement.Client" Version="1.11.0" />
<PackageReference Include="MAVN.Service.PaymentManagement.Contract" Version="1.11.0" />
<PackageReference Include="StackExchange.Redis" Version="2.1.30" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using Common.Log;
using Lykke.Common.Log;
using Lykke.RabbitMqBroker.Subscriber;
using MAVN.Service.PaymentManagement.Contract;
using MAVN.Service.SmartVouchers.Domain.Services;

namespace MAVN.Service.SmartVouchers.DomainServices.RabbitSubscribers
{
// TODO replace object with required message type
public class RabbitSubscriber : JsonRabbitSubscriber<object>
public class RabbitSubscriber : JsonRabbitSubscriber<PaymentCompletedEvent>
{
private readonly ILog _log;
private readonly IVouchersService _voucherService;

public RabbitSubscriber(
string connectionString,
string exchangeName,
string queueName,
ILogFactory logFactory)
ILogFactory logFactory,
IVouchersService voucherService)
: base(connectionString, exchangeName, queueName, logFactory)
{
_log = logFactory.CreateLog(this);
_voucherService = voucherService;
}

protected override async Task ProcessMessageAsync(object message)
protected override async Task ProcessMessageAsync(PaymentCompletedEvent evt)
{
await Task.CompletedTask; // TODO replace this with proper message handling
await _voucherService.ProcessPaymentRequestAsync(Guid.Parse(evt.PaymentRequestId));

_log.Info($"Handled {typeof(object).Name}", message);
_log.Info($"Handled {typeof(object).Name}", evt);
}
}
}
11 changes: 6 additions & 5 deletions src/MAVN.Service.SmartVouchers/Modules/RabbitMqModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Lykke.RabbitMqBroker.Publisher;
using Lykke.RabbitMqBroker.Subscriber;
using Lykke.SettingsReader;
using MAVN.Service.PaymentManagement.Contract;
using MAVN.Service.SmartVouchers.Contract;

namespace MAVN.Service.SmartVouchers.Modules
Expand All @@ -13,7 +14,7 @@ namespace MAVN.Service.SmartVouchers.Modules
public class RabbitMqModule : Module
{
private const string PubExchangeName = "lykke.smart-vouchers.vouchersold";
private const string SubExchangeName = "REPLACE THIS WITH PROPER EXCHANGE NAME"; // TODO pass proper exchange name
private const string SubExchangeName = "lykke.payment.completed"; // TODO pass proper exchange name

private readonly RabbitMqSettings _settings;

Expand Down Expand Up @@ -41,10 +42,10 @@ private void RegisterRabbitMqPublishers(ContainerBuilder builder)

private void RegisterRabbitMqSubscribers(ContainerBuilder builder)
{
//builder.RegisterJsonRabbitSubscriber<RabbitSubscriber, object>( // TODO replace object with proper message type
// _settings.Subscribers.ConnectionString,
// SubExchangeName,
// nameof(SmartVouchers).ToLower()); // this could be changed if needed
builder.RegisterJsonRabbitSubscriber<RabbitSubscriber, PaymentCompletedEvent>(
_settings.Subscribers.ConnectionString,
SubExchangeName,
nameof(SmartVouchers).ToLower()); // this could be changed if needed
}
}
}

0 comments on commit fd9a586

Please sign in to comment.