Task GetMessageHandlerTask(EnvelopeBusMessage message) { return new Task(() => { using (IContainer nested = ObjectFactory.Container.GetNestedContainer()) { ICommandEnvelopeProcessingAuditRepository _processingAudit = nested.GetInstance<ICommandEnvelopeProcessingAuditRepository>(); try { var audit = _processingAudit.GetById(message.MessageId); if (audit != null) { _processingAudit.SetStatus(message.MessageId,EnvelopeProcessingStatus.SubscriberProcessBegin, audit.LastExecutedCommand); Console.WriteLine(message.MessageId.ToString()); _log.InfoFormat("Received messageid {0} from queue {1} ", message.MessageId.ToString(), "Q" + ConfigurationManager.AppSettings["MQName"]); IHandleMessage _handleMessage = nested.GetInstance<IHandleMessage>(); // _handleMessage.Handle(message); } } catch (Exception ex) { _processingAudit.SetStatus(message.MessageId, EnvelopeProcessingStatus.MarkedForRetry,0); _log.Error("Command Lost " + message.MessageId.ToString(), ex); } } }); }
public void Go() { _log.Info("Add Retries message to queue"); EnvelopeBusMessage bm = new EnvelopeBusMessage { MessageId = Guid.NewGuid(), DocumentTypeId = (int)SystemCommandType.AddRetriesToQ, BodyJson = "", SendDateTime = DateTime.Now.ToString(), IsSystemMessage = true }; IBusPublisher bp = ObjectFactory.GetInstance<IBusPublisher>(); ICCAuditRepository _auditRepository = ObjectFactory.GetInstance<ICCAuditRepository>(); ; try { bp.Publish(bm); //_auditRepository.Add(new CCAuditItem //{ // Action = "RetryCommand", // CostCentreId = costcentreId, // DateInsert = DateTime.Now, // Id = Guid.NewGuid(), // Info = info, // Result = results, //}); } catch (Exception ex) { _log.Info("Failed to add retry command to q", ex); } }
public void Handle(EnvelopeBusMessage message) { try { _subscriber.Handle(message); } catch (Exception ex) { _log.Error("Failed to handle message " + message.MessageId, ex); } }
public HttpResponseMessage Post(JObject jcommand) { var responseBasic = new ResponseBasic(); responseBasic.Status = false; HttpStatusCode returnCode = HttpStatusCode.OK; try { responseBasic.ResultInfo = "invalid jsoncommand"; string json = jcommand.ToString(); CommandEnvelope envelope = JsonConvert.DeserializeObject<CommandEnvelope>(json); responseBasic.ResultInfo = "valid jsoncommand"; bool isValid = envelope != null; _log.Info("responseBasic.ResultInfo " + responseBasic.ResultInfo); if (isValid) { if (!_costCentreApplicationService.IsCostCentreActive(envelope.GeneratedByCostCentreApplicationId)) { responseBasic.Status=false; returnCode = HttpStatusCode.OK; responseBasic.Result = "Inactive CostCentre Application Id"; _log.InfoFormat("Cost centre is not active for envelope id {0} ccId {1} ccid",envelope.Id, envelope.GeneratedByCostCentreApplicationId,envelope.GeneratedByCostCentreId); return Request.CreateResponse(returnCode, responseBasic); } _log.InfoFormat("EnvelopeId {0} " ,envelope.Id.ToString()); envelope.EnvelopeArrivedAtServerTick = DateTime.Now.Ticks; var message = new EnvelopeBusMessage { DocumentTypeId = envelope.DocumentTypeId, MessageId = envelope.Id, BodyJson = JsonConvert.SerializeObject(envelope), SendDateTime = DateTime.Now.ToString(), IsSystemMessage = envelope.IsSystemEnvelope }; var envelopeProcessingAudit = new CommandEnvelopeProcessingAudit { GeneratedByCostCentreApplicationId = envelope.GeneratedByCostCentreApplicationId, DateInserted = DateTime.Now, Id = envelope.Id, JsonEnvelope = message.BodyJson, RetryCounter = 0, Status = EnvelopeProcessingStatus.OnQueue, SendDateTime = message.SendDateTime, DocumentId = envelope.DocumentId, ParentDocumentId = envelope.ParentDocumentId, DocumentType = (DocumentType) envelope.DocumentTypeId, EnvelopeGeneratedTick = envelope.EnvelopeGeneratedTick, EnvelopeArrivalAtServerTick = envelope.EnvelopeArrivedAtServerTick, EnvelopeProcessOnServerTick = 0, GeneratedByCostCentreId = envelope.GeneratedByCostCentreId, RecipientCostCentreId = envelope.RecipientCostCentreId, LastExecutedCommand = 0, NumberOfCommand = envelope.CommandsList.Count }; envelopeProcessingAudit.DocumentTypeName = envelopeProcessingAudit.DocumentType.ToString(); if (_commandEnvelopeProcessingAuditRepository.IsConnected()) { var exist = _commandEnvelopeProcessingAuditRepository.GetById(envelope.Id); if (exist == null) { _commandEnvelopeProcessingAuditRepository.AddCommand(envelopeProcessingAudit); _busPublisher.Publish(message); } else { _log.InfoFormat("EnvelopeId {0} Already Published", envelope.Id.ToString()); } _log.InfoFormat("EnvelopeId {0} Published", envelope.Id.ToString()); responseBasic.Status = true; responseBasic.Result = "Envelope Processed"; _log.Info(" responseBasic.Result " + responseBasic.Result); } else { responseBasic.Result = "Processing Failed"; responseBasic.ErrorInfo = "Mongo down"; _log.Info(" responseBasic.ErrorInfo " + responseBasic.ErrorInfo); } } } catch (Exception ex) { responseBasic.Result = "Processing Failed"; responseBasic.ErrorInfo = ex.Message; _log.Info(" responseBasic.Result" + responseBasic.Result); _log.Info(" responseBasic.ErrorInfo " + responseBasic.ErrorInfo); } HttpResponseMessage response = Request.CreateResponse(returnCode, responseBasic); return response; }
public void Publish(EnvelopeBusMessage busMessage) { throw new NotImplementedException(); }
private void AddToMongoDB(CommandEnvelope envelope) { envelope.EnvelopeArrivedAtServerTick = DateTime.Now.Ticks; var envelopeProcessingAudit = new CommandEnvelopeProcessingAudit { GeneratedByCostCentreApplicationId =Guid.Empty, DateInserted = DateTime.Now, Id = envelope.Id, JsonEnvelope = JsonConvert.SerializeObject(envelope), RetryCounter = 0, Status = EnvelopeProcessingStatus.OnQueue, DocumentId = envelope.DocumentId, ParentDocumentId = envelope.ParentDocumentId, DocumentType = (DocumentType)envelope.DocumentTypeId, EnvelopeGeneratedTick = envelope.EnvelopeGeneratedTick, EnvelopeArrivalAtServerTick = DateTime.Now.Ticks, EnvelopeProcessOnServerTick = 0, GeneratedByCostCentreId = envelope.GeneratedByCostCentreId, RecipientCostCentreId = envelope.RecipientCostCentreId, LastExecutedCommand = 0, NumberOfCommand = envelope.CommandsList.Count }; envelopeProcessingAudit.DocumentTypeName = envelopeProcessingAudit.DocumentType.ToString(); _commandProcessingAuditRepository.AddCommand(envelopeProcessingAudit); var message = new EnvelopeBusMessage { DocumentTypeId = envelope.DocumentTypeId, MessageId = envelope.Id, BodyJson = JsonConvert.SerializeObject(envelope), SendDateTime = DateTime.Now.ToString(), }; _busPublisher.Publish(message); }