public virtual void Consumer_ReceiveMessage(IBasicGetResult message) { ContinueProcessing = false; if (message == null) { return; // queue is empty } Message = CustomJsonSerializer.BytesToMessage <T>(message.Body); CorrelationId = message.BasicProperties.CorrelationId; RoutingKey = message.RoutingKey; if (message.Body.Count() == 0) { Log.Error( "SubscriberBase: Consumer_ReceiveMessage(message) - message.Body contains no data for message id {0}", message.BasicProperties.MessageId); } if (Message != null) { ContinueProcessing = true; return; } if (message.Body.Count() > 0) { Log.Error("SubscriberBase: Consumer_ReceiveMessage(message) - message.Body contains data which is not compatible with {0} for message id {1}", typeof(T).ToString(), message.BasicProperties.MessageId); } InvalidExchange.SendMessage(message.Body, InvalidRoutingKey, ""); }
protected virtual void Dispose(bool disposing) { if (disposed) { return; } Log.Verbose("Disposing of Processing Service {0}", GetType().ToString()); if (disposing) { Consumer.Dispose(); Exchange.Dispose(); InvalidExchange.Dispose(); } disposed = true; }
public override void Consumer_ReceiveMessage(IBasicGetResult message) { base.Consumer_ReceiveMessage(message); if (!ContinueProcessing) { return; } var request = Message; Log.Information("Processing CorrectCodelineRequest '{@request}', '{@correlationId}'", request, CorrelationId); try { //Mapping queue table var queue = QueueMapper.Map(request); queue.CorrelationId = CorrelationId; queue.RoutingKey = RoutingKey; //Mapping voucher fields var vouchers = VoucherMapper.Map(request).ToList(); var jobIdentifier = CorrelationId; var batchNumber = string.IsNullOrEmpty(request.voucherBatch.scannedBatchNumber) ? queue.S_BATCH : request.voucherBatch.scannedBatchNumber; var processingDate = request.voucher.First().processingDate; //Peform image merge for Dips var imageMergeHelper = new ImageMergeHelper(Configuration); imageMergeHelper.EnsureMergedImageFilesExist(jobIdentifier, batchNumber, processingDate); imageMergeHelper.PopulateMergedImageInfo(jobIdentifier, batchNumber, vouchers); //Mapping index fields var dbIndexes = DbIndexMapper.Map(request); using (var dbConnection = new SqlConnection(Configuration.SqlConnectionString)) { using (var dipsDbContext = new DipsDbContext(dbConnection)) { using (var tx = dipsDbContext.BeginTransaction()) { try { //Adding to queue table dipsDbContext.Queues.Add(queue); Log.Verbose("Adding new queue {@batchNumber} to the database", queue.S_BATCH); dipsDbContext.SaveChanges(); //Adding to voucher table foreach (var voucher in vouchers) { dipsDbContext.NabChqPods.Add(voucher); Log.Verbose( "Adding new voucher {@batchNumber} - {@sequenceNumber} to the database", voucher.S_BATCH, voucher.S_SEQUENCE); } dipsDbContext.SaveChanges(); //Adding to index table foreach (var dbIndex in dbIndexes) { dipsDbContext.DbIndexes.Add(dbIndex); Log.Verbose( "Adding new db index {@batchNumber} - {@sequenceNumber} to the database", dbIndex.BATCH, dbIndex.SEQUENCE); } dipsDbContext.SaveChanges(); tx.Commit(); InvalidExchange.SendMessage(message.Body, RecoverableRoutingKey, CorrelationId); Log.Information( "Successfully processed CorrectCodelineRequest '{@batchNumber}', '{@jobIdentifier}'", batchNumber, jobIdentifier); } catch (OptimisticConcurrencyException) { //this is to handle the race condition where more than instance of this service is running at the same time and tries to update the row. //basically ignore the message by loggin a warning and rolling back. //if this row was not included by mistake (e.g. it should be included), it will just come in in the next batch run. Log.Warning( "Could not create a CorrectCodelineRequest '{@CorrectionCodelineRequest}', '{@jobIdentifier}' because the DIPS database row was updated by another connection", request, jobIdentifier); tx.Rollback(); InvalidExchange.SendMessage(message.Body, RecoverableRoutingKey, CorrelationId); } catch (Exception ex) { Log.Error( ex, "Could not complete and create a CorrectCodelineRequest '{@CorrectionCodelineRequest}', '{@jobIdentifier}'", request, jobIdentifier); tx.Rollback(); InvalidExchange.SendMessage(message.Body, RecoverableRoutingKey, CorrelationId); } } } } } catch (Exception ex) { Log.Error(ex, "Error processing CorrectionCodelineRequest {@CorrectionCodelineRequest}", request); InvalidExchange.SendMessage(message.Body, InvalidRoutingKey, CorrelationId); } }
public static void Consumer_ReceiveMessage(IBasicGetResult message) { // Process Message from queue if (message == null) { return; // queue is empty } var batch = CustomJsonSerializer.BytesToMessage <RecogniseBatchCourtesyAmountRequest>(message.Body); //var batch = message; if (message.Body.Count() == 0) { Log.Error( "ProcessingService: Queue_MessageRecieved(message) - message.Body contains no data for message id {0}", message.BasicProperties.MessageId); } if (batch == null) { if (message.Body.Count() > 0) { Log.Error( "ProcessingService: Queue_MessageRecieved(message) - message.Body contains data which is not compatible with RecogniseBatchCourtesyAmountRequest for message id {0}", message.BasicProperties.MessageId); } // need to re-route message to CAR.Invalid queue if (!string.IsNullOrEmpty(InvalidQueueName)) { InvalidExchange.SendMessage(message.Body, InvalidRoutingKey, ""); } return; // acknowledge message to remove from queue; } RoutingKey = message.RoutingKey; if (batch.voucher == null || batch.voucher.Length == 0) { Log.Error( "ProcessingService: Queue_MessageRecieved(message) - there are no vouchers present for message id {0}", message.BasicProperties.MessageId); // need to re-route message to CAR.Invalid queue if (!string.IsNullOrEmpty(InvalidQueueName)) { InvalidExchange.SendMessage(message.Body, InvalidRoutingKey, ""); } return; // acknowledge message to remove from queue; } var ocrBatch = new OcrBatch { JobIdentifier = batch.jobIdentifier, Vouchers = batch.voucher.Select(v => new OcrVoucher { Id = v.documentReferenceNumber, ImagePath = Path.Combine(ImageFilePath, batch.jobIdentifier, string.Format(ImageFileNameTemplate, v.processingDate, v.documentReferenceNumber)), VoucherType = ParseTransactionCode(v.transactionCode) }).ToList() }; // Validate the file path if (!ValidateImageFiles(ocrBatch)) { return; // probably should send to an error queue } Log.Information("Batch {0} received from message queue containing {1} vouchers", ocrBatch.JobIdentifier, ocrBatch.Vouchers.Count()); OcrService.ProcessBatch(ocrBatch); }
public override void Consumer_ReceiveMessage(IBasicGetResult message) { base.Consumer_ReceiveMessage(message); if (!ContinueProcessing) { return; } var request = Message; Log.Information("Processing GetVouchersInformationResponse '{@request}', '{@correlationId}'", request, CorrelationId); try { var jobIdentifier = CorrelationId; var batchNumber = string.Empty; if (request.voucherInformation.Length == 0) { Log.Information("No matching vouchers found GetVouchersInformationResponse '{@batchNumber}', '{@jobIdentifier}'", batchNumber, jobIdentifier); //Mapping responseDone fields var responseDoneOutput = new DipsResponseDone { guid_name = CorrelationId, response_time = DateTime.Now, number_of_results = 0 }; using (var dbConnection = new SqlConnection(Configuration.SqlConnectionString)) using (var dipsDbContext = new DipsDbContext(dbConnection)) { using (var tx = dipsDbContext.BeginTransaction()) { try { //Adding to DipsResponseDone table dipsDbContext.DipsResponseDone.Add(responseDoneOutput); dipsDbContext.SaveChanges(); tx.Commit(); Log.Information("Successfully processed GetVouchersInformationResponse '{@batchNumber}', '{@jobIdentifier}'", batchNumber, jobIdentifier); } catch (OptimisticConcurrencyException) { //this is to handle the race condition where more than instance of this service is running at the same time and tries to update the row. //basically ignore the message by loggin a warning and rolling back. //if this row was not included by mistake (e.g. it should be included), it will just come in in the next batch run. Log.Warning( "Could not create a GetVouchersInformationResponse '{@GetVouchersInformationResponse}', '{@jobIdentifier}' because the DIPS database row was updated by another connection", request, jobIdentifier); tx.Rollback(); } catch (Exception ex) { Log.Error( ex, "Could not complete and create a GetVouchersInformationResponse '{@GetVouchersInformationResponse}', '{@jobIdentifier}'", request, jobIdentifier); tx.Rollback(); } } } } else { //Mapping criteria fields var firstVoucher = request.voucherInformation.First(); var criterias = MapToCriterias(firstVoucher); var jsonPayload = JsonConvert.SerializeObject(criterias); //Mapping responseDone fields var responseDoneOutput = new DipsResponseDone { guid_name = CorrelationId, response_time = DateTime.Now, number_of_results = 1 }; //Mapping responsData fields var responseDataOutput = new DipsResponseData { doc_ref_number = firstVoucher.voucher.documentReferenceNumber, guid_name = CorrelationId, payload = jsonPayload, front_image = System.Text.Encoding.Default.GetString(firstVoucher.voucherImage[0].content), rear_image = System.Text.Encoding.Default.GetString(firstVoucher.voucherImage[1].content) }; using (var dbConnection = new SqlConnection(Configuration.SqlConnectionString)) using (var dipsDbContext = new DipsDbContext(dbConnection)) { using (var tx = dipsDbContext.BeginTransaction()) { try { //Adding to DipsResponseData table dipsDbContext.DipsResponseData.Add(responseDataOutput); Log.Verbose("Adding new response data {@drn} to the database", request.voucherInformation.First().voucher.documentReferenceNumber); dipsDbContext.SaveChanges(); //Adding to DipsResponseDone table dipsDbContext.DipsResponseDone.Add(responseDoneOutput); Log.Verbose("Adding new response data done row to the database"); dipsDbContext.SaveChanges(); tx.Commit(); Log.Information("Successfully processed GetVouchersInformationResponse '{@batchNumber}', '{@jobIdentifier}'", batchNumber, jobIdentifier); } catch (OptimisticConcurrencyException) { //this is to handle the race condition where more than instance of this service is running at the same time and tries to update the row. //basically ignore the message by loggin a warning and rolling back. //if this row was not included by mistake (e.g. it should be included), it will just come in in the next batch run. Log.Warning( "Could not create a GetVouchersInformationResponse '{@GetVouchersInformationResponse}', '{@jobIdentifier}' because the DIPS database row was updated by another connection", request, jobIdentifier); tx.Rollback(); InvalidExchange.SendMessage(message.Body, RecoverableRoutingKey, CorrelationId); } catch (Exception ex) { Log.Error( ex, "Could not complete and create a GetVouchersInformationResponse '{@GetVouchersInformationResponse}', '{@jobIdentifier}'", request, jobIdentifier); tx.Rollback(); InvalidExchange.SendMessage(message.Body, RecoverableRoutingKey, CorrelationId); } } } } } catch (Exception ex) { Log.Error(ex, "Error processing GetVouchersInformationResponse {@GetVouchersInformationResponse}", request); InvalidExchange.SendMessage(message.Body, InvalidRoutingKey, CorrelationId); } }