using LCU.Library.Internal.LcuMassTransitModels; using MassTransit; using Newtonsoft.Json; using ReserveManagementSystemApi.Configurations; using ReserveManagementSystemLib.Models; namespace ReserveManagementSystemApi.Services.QueueServices { public class QueueRmsActiveLoanService : IQueueRmsActiveLoanService { private readonly ISendEndpoint _sendEndpoint; private readonly ReceiveEndpointConfiguration _rmsActiveLoanImportReceiveEndpoint; public QueueRmsActiveLoanService(IBusControl busControl, ReceiveEndpointConfigurations receiveEndpointConfigurations) { _rmsActiveLoanImportReceiveEndpoint = receiveEndpointConfigurations.RmsActiveLoanReceiveEndpoint; _sendEndpoint = busControl.GetSendEndpoint(_rmsActiveLoanImportReceiveEndpoint.ReceiveEndpointUri).Result; } public async Task QueueRmsActiveLoanServiceRequest(RmsActiveImportRequest request) { try { var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30)); await _sendEndpoint.Send(request, cancellationTokenSource.Token); } catch (Exception exception) { var message = "Failed to Queue RmsActiveLoanImport Request. " + $"RmsActiveLoanImport: {JsonConvert.SerializeObject(request)}"; Log.Error(exception, message); throw new ServiceException($"{message}, Exception Message: {exception.Message}"); } } } }