Beispiel #1
0
 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, "");
 }
Beispiel #2
0
        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);
        }