private static void OcrService_BatchComplete(object sender, OcrBatch batch) { //Console.WriteLine("Batch {0} completed", batch.JobIdentifier); // publish result to outgoing queue/exchange var messageBatch = new RecogniseBatchCourtesyAmountResponse { jobIdentifier = batch.JobIdentifier, voucher = batch.Vouchers.Select(v => new RecogniseCourtesyAmountResponse { documentReferenceNumber = v.Id, capturedAmount = v.AmountResult.Result ?? "0", amountConfidenceLevel = v.AmountResult.Score ?? "0", amountRegionOfInterest = new RegionOfInterest { height = v.AmountResult.Location.Height, left = v.AmountResult.Location.Left, top = v.AmountResult.Location.Top, width = v.AmountResult.Location.Width } }).ToArray() }; //MessageBus.Publish(messageBatch, RoutingKey); //Queue.PublishToExchange(OutboundExchangeName, batch.JobIdentifier, RoutingKey, CustomJsonSerializer.MessageToBytes(messageBatch)); Exchange.SendMessage(CustomJsonSerializer.MessageToBytes(messageBatch), RoutingKey, batch.JobIdentifier); }
public void ThenThereWillBeAMessageInLombard_Service_Outclearings_Recognisecourtesyamount_Response_QueueWithJobIdentifierAndFollowingCARResult(string jobId, Table table) { var vouchers = table.CreateSet <RecogniseCourtesyAmountResponse>(); var expectedMessage = new RecogniseBatchCourtesyAmountResponse { jobIdentifier = jobId, voucher = vouchers.ToArray() }; var task = AutoReadCarBus.GetSingleResponseAsync(10, jobId); task.Wait(); var response = task.Result; Assert.IsNotNull(response); Assert.AreEqual(expectedMessage.jobIdentifier, response.jobIdentifier); Assert.AreEqual(expectedMessage.voucher.Length, response.voucher.Length); table.CompareToSet(response.voucher); }
public async Task ProcessAsync(CancellationToken cancellationToken) { try { //messageBus.AcknowledgeMessageDelivered(request); var batchInfo = courtesyAmountRequestBatchInfoMapper.Map(Message); // TODO: Validate info //Log.Error("Queue message {@message} does not contain correct information. Cannot be processed.", message); #region Verify the files in BatchInfo //Log.Information("Start processing batch with correlation Id '{0}'.", batchInfo.CorrelationId); // Validate the file path Parallel.ForEach(batchInfo.ChequeImageInfos, item => { if (!fileSystem.File.Exists(item.Urn)) { item.Status = 1; item.Succes = false; item.ErrorMessage = string.Format("Image file {0} does not exists.", item.Urn); // TODO: Notify anyone? Log.Information(item.ErrorMessage); } }); #endregion var listResponses = new ConcurrentBag <RecogniseCourtesyAmountResponse>(); Parallel.ForEach(batchInfo.ChequeImageInfos, item => { //Log.Information("Start processing Cheque Image at '{0}'.", item.URN); if (item.Status == 0) { var result = ProcessChequeIcrRequest(item).Result; //Log.Debug("File '{0}' has been queued.", item.URN); if (!result.Success) { listResponses.Add(result); } } else { listResponses.Add(new RecogniseCourtesyAmountResponse { DocumentReferenceNumber = item.DocumentReferenceNumber, Success = false, ErrorMessage = item.ErrorMessage }); } }); Parallel.ForEach(batchInfo.ChequeImageInfos, item => { var result = GetLastChequeOcrResponse().Result; if (result != null) { //Log.Debug("CAR for File '{0}' was {1}, score was {2}.", result.documentReferenceNumber, result.capturedAmount, result.confidenceLevel); listResponses.Add(result); } }); var remaining = GetLastChequeOcrResponse().Result; while (remaining != null) { Log.Debug("CAR for remaining File was {0}.", remaining.CapturedAmount); listResponses.Add(remaining); remaining = GetLastChequeOcrResponse().Result; } // publish to outbound queue var batchResponse = new RecogniseBatchCourtesyAmountResponse(); batchResponse.Voucher = listResponses.ToArray(); await exchangePublisher.PublishAsync(batchResponse); //.PopulateOutboundQueue(batchResponse, inboundMessage.BasicProperties.CorrelationId); } catch (Exception ex) // Specific exceptions { Log.Error(ex, "Error occurred while processing a message."); throw; } }