Example #1
0
 public void Publish(BusMessage busMessage)
 {
     byte[] _busMessage = busMessage.ToBinary();
     CloudQueue queue = GetQueue();
     CloudQueueMessage message = new CloudQueueMessage(_busMessage);
     queue.AddMessage(message);
 }
Example #2
0
        public void Handle(BusMessage message)
        {
            try
            {
                _subscriber.Handle(message);
            }
            catch (Exception ex)
            {
                _log.Error("Failed to handle message " + message.MessageId, ex);
            }

        }
 private void Republish(IEnumerable<CommandProcessingAudit> commmands)
 {
     foreach (var cmd in commmands)
     {
         BusMessage msg = new BusMessage
                              {
                                  BodyJson = cmd.JsonCommand,
                                  CommandType = cmd.CommandType,
                                  IsSystemMessage = false,
                                  MessageId = cmd.Id,
                                  SendDateTime = cmd.SendDateTime,
                              };
         cmd.Status = CommandProcessingStatus.OnQueue;
         _busPublisher.Publish(msg);
         _commandProcessingAuditRepository.SetCommandStatus(cmd.Id, CommandProcessingStatus.OnQueue);
     }
 }
        public HttpResponseMessage Run(JObject jcommand)
        {

            Guid commandId = Guid.Empty;
            var responseBasic = new ResponseBasic();
            HttpStatusCode returnCode = HttpStatusCode.OK;
            try
            {
                responseBasic.ResultInfo = "invalid jsoncommand";
                DocumentCommand command = JsonConvert.DeserializeObject<DocumentCommand>(jcommand.ToString());
                responseBasic.ResultInfo = "valid jsoncommand";
                _log.InfoFormat("Received command id {0} : command type {1} : document id {2}", command.CommandId, command.CommandTypeRef, command.DocumentId);
                bool isValid = command != null;

                commandId = command.CommandId;
                //if (isValid && !_costCentreApplicationService.IsCostCentreActive(command.CommandGeneratedByCostCentreApplicationId))
                //{
                //    isValid = false;
                //    returnCode = HttpStatusCode.NotAcceptable;
                //    responseBasic.Result = "Inactive CostCentre Application Id ";
                //    _log.InfoFormat("Cost centre is not active for command id {0} cost centre application id {1}", command.CommandId, command.CommandGeneratedByCostCentreApplicationId);
                //}
                if (isValid)
                {
                    _log.InfoFormat("CommandId {0} Placed on bus", command.CommandId);
                    var message = new BusMessage
                    {
                        CommandType = command.CommandTypeRef,
                        MessageId = command.CommandId,
                        BodyJson = JsonConvert.SerializeObject(command),
                        SendDateTime = DateTime.Now.ToString(),
                        IsSystemMessage = command.IsSystemCommand
                    };
                    var commandProcessingAudit = new CommandProcessingAudit
                    {
                        CommandType = command.CommandTypeRef,
                        CostCentreApplicationId = command.CommandGeneratedByCostCentreApplicationId,
                        CostCentreCommandSequence = command.CommandSequence,
                        DateInserted = DateTime.Now,
                        Id = command.CommandId,
                        JsonCommand = message.BodyJson,
                        RetryCounter = 0,
                        Status = CommandProcessingStatus.OnQueue,
                        SendDateTime = message.SendDateTime,
                        DocumentId = command.DocumentId,
                        ParentDocumentId = command.PDCommandId
                    };

                    _busPublisher.Publish(message);
                    AuditCCHit(command.CommandGeneratedByCostCentreId, "CommandProcessing",
                               string.Format("Publish : {0} Command {1} of Type {2}",
                                             CommandProcessingStatus.OnQueue.ToString(), command.CommandId.ToString(),
                                             message.CommandType), CommandProcessingStatus.OnQueue.ToString());
                    _commandProcessingAuditRepository.AddCommand(commandProcessingAudit);
                    responseBasic.Result = "Command Processed";


                }
            }
            catch (Exception ex)
            {
                responseBasic.Result = "Processing Failed";
                responseBasic.ErrorInfo = ex.Message;
                _log.Error("Failed to process command", ex);
            }
            HttpResponseMessage response = Request.CreateResponse(returnCode, responseBasic);
            _log.InfoFormat("ResponseMessage : commandId = {0}  : response code = {1}  : Response Result = {2}", commandId, returnCode, responseBasic.Result);
            return response;
        }
Example #5
0
 /// <summary>
 /// There is a slight lag on updating the CommandProcessingAudit.Status. 
 /// This is a check to ensure that a command with status Complete does not get executed twice
 /// </summary>
 private bool CheckValidDequeueProcess(CloudQueueMessage msg, ICommandProcessingAuditRepository _processingAudit,BusMessage busMessage)
 {
     bool validDequeueProcess = true;
     if (msg.DequeueCount > 1)
     {
         _logger.InfoFormat("More than one dequeue count, test message status ");
         CommandProcessingAudit auditDeque = _processingAudit.GetByCommandId(busMessage.MessageId);
         if (auditDeque.Status == CommandProcessingStatus.Complete)
         {
             _logger.Info("Dequeue validation detected CommandProcessingStatus.Complete. Dequeueing");
             _incomingCommandQueue.DeleteMessage(msg);
             validDequeueProcess = false;
         }
         else
         {
             _logger.Info("Valid dequeue process .....");
         }
     }
     return validDequeueProcess;
 }
Example #6
0
        private ResponseBasic ProcessMessage(string commandType, string jsoncommand, string sendDateTime, string source)
        {
            string result = "";
            string errorInfo = "";
            Guid ccId = Guid.Empty;
            _log.InfoFormat("Processing command : {0} with {1} from source {2} ", commandType, jsoncommand, source);
            try
            {
                DateTime _sendDateTime = _commandDeserialize.DeserializeSendDateTime(sendDateTime);
                ICommand deserializedCommand = _commandDeserialize.DeserializeCommand(commandType, jsoncommand);

                bool isValid = deserializedCommand != null;
                result = isValid ? "OK" : "Invalid";
                _log.InfoFormat("Deserialization is valid " + result);
                errorInfo = isValid ? "" : "Failed to deserialize " + commandType;

                if (isValid && !_costCentreApplicationService.IsCostCentreActive(deserializedCommand.CommandGeneratedByCostCentreApplicationId))
                {
                    isValid = false;
                    result = "Invalid";
                    errorInfo = "Inactive CostCentre Application Id ";
                }
                if (isValid && !QHealth.IsQueueHealthy)
                {
                    isValid = false;
                    result = "Invalid";
                    errorInfo = "Message Q not available";
                }

                if (isValid)
                {
                    ccId = deserializedCommand.CommandGeneratedByCostCentreId;
                    deserializedCommand.SendDateTime = _sendDateTime;
                    _log.Info("Client SendDateTime " + sendDateTime);
                    _log.InfoFormat("CommandId {0} Placed on bus", deserializedCommand.CommandId);
                    var message = new BusMessage
                    {
                        CommandType = commandType,
                        MessageId = deserializedCommand.CommandId,
                        BodyJson = jsoncommand,
                        SendDateTime = sendDateTime
                    };
                    var commandProcessingAudit = new CommandProcessingAudit
                                                                        {
                                                                            CommandType = commandType,
                                                                            CostCentreApplicationId = deserializedCommand.CommandGeneratedByCostCentreApplicationId,
                                                                            CostCentreCommandSequence = deserializedCommand.CommandSequence,
                                                                            DateInserted = DateTime.Now,
                                                                            Id = deserializedCommand.CommandId,
                                                                            JsonCommand = jsoncommand,
                                                                            RetryCounter = 0,
                                                                            Status = CommandProcessingStatus.OnQueue,
                                                                            SendDateTime=sendDateTime,
                                                                            DocumentId = deserializedCommand.DocumentId,
                                                                            ParentDocumentId=deserializedCommand.PDCommandId
                                                                        };

                   
                    _busPublisher.Publish(message);
                    AuditCCHit(deserializedCommand.CommandGeneratedByCostCentreId, "CommandProcessing", string.Format("Publish : {0} Command {1} of Type {2}", CommandProcessingStatus.OnQueue.ToString(), deserializedCommand.CommandId.ToString(), message.CommandType), CommandProcessingStatus.OnQueue.ToString());
                   _commandProcessingAuditRepository.AddCommand(commandProcessingAudit);
                }
                else
                    _log.Error(errorInfo);
            }
            catch (Exception ex)
            {
                result = "Invalid";
                _log.InfoFormat("ERROR Processing command : {0}", commandType);
                _log.Error(ex);
            }

            ResponseBasic responce = new ResponseBasic { Result = result, ErrorInfo = errorInfo };
            _log.Info("Final responce " + JsonConvert.SerializeObject(responce));
            AuditCCHit(ccId, "slprocess", "CommandType : " + commandType, result);
            return responce;
        }