public void Handle(EnvelopeBusMessage busMessage) { DateTime dtSent = DateTime.Parse(busMessage.SendDateTime); SystemCommandType systemCommandType = (SystemCommandType)busMessage.DocumentTypeId; var envelope = JsonConvert.DeserializeObject<CommandEnvelope>(busMessage.BodyJson); switch (systemCommandType) { case SystemCommandType.AddRetriesToQ: if (DateTime.Now.Subtract(dtSent) < new TimeSpan(0, 0, 10, 0)) //only process message sent in the last 10 mintuts _qAddRetryCommandHandler.Execute(); break; } if (envelope!=null && envelope.CommandsList.Any(s=>s.Command is ReRouteDocumentCommand)) { foreach (var command in envelope.CommandsList.Where(s => s.Command is ReRouteDocumentCommand).Select(s => s.Command)) { _reRouteDocumentCommandHandler.Execute(command as ReRouteDocumentCommand); } } }
public void Handle(EnvelopeBusMessage message) { Stopwatch handlerTimer = new Stopwatch(); handlerTimer.Start(); var docType = (DocumentType) message.DocumentTypeId; _logger.InfoFormat(" Subscriber Processing Envelope : {0} with {1} ", docType, message.BodyJson); EnvelopeProcessingStatus currentStatus = EnvelopeProcessingStatus.SubscriberProcessBegin; int lastExecutedCommand = 0; CommandEnvelope envelope = JsonConvert.DeserializeObject<CommandEnvelope>(message.BodyJson); try { var audit = _envelopeProcessingAuditRepository.GetById(envelope.Id); lastExecutedCommand = audit.LastExecutedCommand; Audit("CommandEnvelopeProcessing", string.Format("Handle : {0} Envelope {1} of Type {2}", currentStatus.ToString(), envelope.Id.ToString(), docType), currentStatus.ToString(), envelope.GeneratedByCostCentreId); if (!string.IsNullOrWhiteSpace(message.SendDateTime)) { DateTime _sendDateTime = _commandDeserialize.DeserializeSendDateTime(message.SendDateTime); // envelope.SendDateTime = _sendDateTime; } if (envelope.CommandsList.Any()) { // envelope = _documentHelper.GetExternalRef(envelope); foreach (var envelopeItem in envelope.CommandsList.OrderBy(s=>s.Order) ) { CommandType commandType = GetCommandType(envelopeItem.Command.CommandTypeRef); _runCommandOnRequestInHostedEnvironment.RunCommandInHostedenvironment(envelopeItem.Command); if (commandType == CommandType.CreateMainOrder) { RouteDocumentExternalRef(envelope.DocumentId,envelope.GeneratedByCostCentreId,envelope.RecipientCostCentreId, envelopeItem); } lastExecutedCommand = envelopeItem.Order; } _commandEnvelopeRouteOn.AddCommandEnvelopeRouteCentre(envelope); } currentStatus = EnvelopeProcessingStatus.Complete; // _busPublisher.SignalComplete(command); } catch (MarkForRetryException ex) { _logger.Error("Markfor retry", ex); currentStatus = EnvelopeProcessingStatus.MarkedForRetry; } catch (CommandAlreadyExecutedException ex) { _logger.Error("Command already executed", ex); currentStatus = EnvelopeProcessingStatus.Failed; } catch (Exception ex) { //record to command audit that message failed to be processed _logger.Error("Command processing error ", ex); currentStatus = EnvelopeProcessingStatus.MarkedForRetry; //throw ex; } Audit("CommandEnvelopeProcessing", string.Format("Handle : {0} Envelope {1} of Type {2}", currentStatus.ToString(), envelope.Id.ToString(), docType), currentStatus.ToString(), envelope.GeneratedByCostCentreId); // Audit("CommandProcessing", string.Format("Handle : {0} Command {1} of Type {2}", currentStatus.ToString(), envelope.CommandId.ToString(), message.CommandType), currentStatus.ToString(), envelope.CommandGeneratedByCostCentreId); _envelopeProcessingAuditRepository.SetStatus(message.MessageId, currentStatus,lastExecutedCommand); //record that message was processed successfully handlerTimer.Stop(); // _logger.InfoFormat("Total Request Time(m/s) {0} for command {1} ", handlerTimer.Elapsed.TotalMilliseconds, message.CommandType); }
public void Publish(EnvelopeBusMessage busMessage) { _busSubscriber.Handle(busMessage); }
public void Publish(EnvelopeBusMessage busMessage) { var exchange = Exchange.DeclareTopic(_exName); using (var channel = _bus.OpenPublishChannel()) { channel.Publish<EnvelopeBusMessage>(exchange, "", new Message<EnvelopeBusMessage>(busMessage)); _log.InfoFormat("Message for Envelopr id {0} published on exchange {1}", busMessage.MessageId, _exName); } }
public void Publish(EnvelopeBusMessage busMessage) { throw new NotImplementedException(); }