public void Execute(Envelope envelope, IEnvelopeContext context) { envelope.Message = null; // Prevent the error from throwing again. context.SendFailureAcknowledgement(envelope, "Deserialization failed"); context.Error(envelope.CorrelationId, _exception.Message, _exception); envelope.Callback.MoveToErrors(new ErrorReport(envelope, _exception)); }
public void Execute(Envelope envelope, IEnvelopeContext context) { context.SendFailureAcknowledgement(envelope, "Moved message {0} to the Error Queue.\n{1}".ToFormat(envelope.CorrelationId, _exception)); var report = new ErrorReport(envelope, _exception); envelope.Callback.MoveToErrors(report); }
// virtual for testing as usual public virtual async Task<IContinuation> FindContinuation(Envelope envelope, IEnvelopeContext context) { foreach (var handler in _handlers) { var continuation = await handler.Handle(envelope).ConfigureAwait(false); if (continuation != null) { context.DebugMessage(() => new EnvelopeContinuationChosen { ContinuationType = continuation.GetType(), HandlerType = handler.GetType(), Envelope = envelope.ToToken() }); return continuation; } } // TODO - add rules for what to do when we have no handler context.DebugMessage(() => new EnvelopeContinuationChosen { ContinuationType = typeof(MoveToErrorQueue), HandlerType = typeof(HandlerPipeline), Envelope = envelope.ToToken() }); return new MoveToErrorQueue(new NoHandlerException(envelope.Message.GetType())); }
public virtual async Task Invoke(Envelope envelope, IEnvelopeContext context) { envelope.Attempts++; // needs to be done here. IContinuation continuation = null; try { continuation = await FindContinuation(envelope, context).ConfigureAwait(false); continuation.Execute(envelope, context); } catch (EnvelopeDeserializationException ex) { new DeserializationFailureContinuation(ex).Execute(envelope, context); } catch (AggregateException e) { e.Flatten().InnerExceptions.Each(ex => { envelope.Callback.MarkFailed(e); var message = "Failed while invoking message {0} with continuation {1}".ToFormat(envelope.Message ?? envelope, (object)continuation ?? "could not find continuation"); context.Error(envelope.CorrelationId, message, e); }); } catch (Exception e) { envelope.Callback.MarkFailed(e); // TODO -- watch this one. var message = "Failed while invoking message {0} with continuation {1}".ToFormat(envelope.Message ?? envelope, (object)continuation ?? "could not find continuation"); context.Error(envelope.CorrelationId, message, e); } }
public override void Execute(Envelope envelope, IEnvelopeContext context) { context.InfoMessage(() => new MessageSuccessful { Envelope = envelope.ToToken() }); envelope.Callback.MarkSuccessful(); }
public Task Handle(Envelope envelope, IEnvelopeContext context) { _source.SetResult(envelope); Handled.Add(envelope); return(Task.CompletedTask); }
public void Execute(Envelope envelope, IEnvelopeContext context) { _task = Task.Factory.StartNew(() => { var continuation = _inner(); continuation.Execute(envelope, context); }); }
// virtual for testing as usual public virtual IContinuation FindContinuation(Envelope envelope, IEnvelopeContext context) { foreach (var handler in _handlers) { var continuation = handler.Handle(envelope); if (continuation != null) { context.DebugMessage(() => new EnvelopeContinuationChosen { ContinuationType = continuation.GetType(), HandlerType = handler.GetType(), Envelope = envelope.ToToken() }); return(continuation); } } // TODO - add rules for what to do when we have no handler context.DebugMessage(() => new EnvelopeContinuationChosen { ContinuationType = typeof(MoveToErrorQueue), HandlerType = typeof(HandlerPipeline), Envelope = envelope.ToToken() }); return(new MoveToErrorQueue(new NoHandlerException(envelope.Message.GetType()))); }
public override void Execute(Envelope envelope, IEnvelopeContext context) { context.SendFailureAcknowledgement(envelope, "No subscriber"); envelope.Callback.MarkSuccessful(); context.InfoMessage(() => new NoHandlerForMessage { Envelope = envelope.ToToken() }); }
public async Task Execute(Envelope envelope, IEnvelopeContext context, DateTime utcNow) { await context.SendFailureAcknowledgement(envelope, $"Moved message {envelope.Id} to the Error Queue.\n{Exception}"); await envelope.Callback.MoveToErrors(envelope, Exception); context.Logger.MovedToErrorQueue(envelope, Exception); }
public Task Execute(Envelope envelope, IEnvelopeContext context, DateTime utcNow) { context.SendFailureAcknowledgement(envelope, $"Moved message {envelope.CorrelationId} to the Error Queue.\n{Exception}"); context.Logger.MessageFailed(envelope, Exception); context.Logger.LogException(Exception, envelope.CorrelationId); var report = new ErrorReport(envelope, Exception); return(envelope.Callback.MoveToErrors(report)); }
public override void Execute(Envelope envelope, IEnvelopeContext context) { try { envelope.Callback.MoveToDelayedUntil(envelope.ExecutionTime.Value); context.InfoMessage(() => new DelayedEnvelopeReceived { Envelope = envelope.ToToken() }); } catch (Exception e) { envelope.Callback.MarkFailed(e); context.Error(envelope.CorrelationId, "Failed to move delayed message to the delayed message queue", e); } }
public void Execute(Envelope envelope, IEnvelopeContext context) { _continuations.Each(x => { try { x.Execute(envelope, context); } catch (Exception e) { context.Error(envelope.CorrelationId, "Failed trying to run continuation {0} as part of error handling".ToFormat(x), e); } }); }
public void Execute(Envelope envelope, IEnvelopeContext context) { context.SendFailureAcknowledgement(envelope, "Chain execution failed"); envelope.Callback.MarkFailed(_exception); context.InfoMessage(() => new MessageFailed {Envelope = envelope.ToToken(), Exception = _exception}); if (envelope.Message == null) { context.Error(envelope.CorrelationId, "Error trying to execute a message of type " + envelope.Headers[Envelope.MessageTypeKey], _exception); } else { context.Error(envelope.CorrelationId, envelope.Message.ToString(), _exception); } }
public Result<object> Process(Sale sale, IEnvelopeContext context) { var envelopeBuilder = new DeliveryEnvelopeBuilder(sale, new PaymentNoteEnvelopeBuilder(context, new ReceiptEnvelopeBuilder(context, new OutletVisitNoteEnvelopeBuilder(context)))); return new Transactor(database).Transact(() => { envelopeBuilder.Build().ForEach(e => envelopeRouter.RouteCommandEnvelope(e)); sale.ConfirmNewPayments(); saleRepository.Save(sale); }); }
public async Task Execute(Envelope envelope, IEnvelopeContext context, DateTime utcNow) { foreach (var continuation in _continuations) { try { await continuation.Execute(envelope, context, utcNow).ConfigureAwait(false); } catch (Exception e) { context.Logger.LogException(e, envelope.Id, $"Failed trying to run continuation {continuation} as part of error handling"); } } }
public void Execute(Envelope envelope, IEnvelopeContext context) { context.SendFailureAcknowledgement(envelope, "Chain execution failed"); envelope.Callback.MarkFailed(_exception); context.InfoMessage(() => new MessageFailed { Envelope = envelope.ToToken(), Exception = _exception }); if (envelope.Message == null) { context.Error(envelope.CorrelationId, "Error trying to execute a message of type " + envelope.Headers[Envelope.MessageTypeKey], _exception); } else { context.Error(envelope.CorrelationId, envelope.Message.ToString(), _exception); } }
public Result<object> Process(Sale sale, IEnvelopeContext context) { var envelopeBuilder = new OrderEnvelopeBuilder(sale, new MainOrderEnvelopeBuilder(context, new ExternalDocRefEnvelopeBuilder(context, new PaymentNoteEnvelopeBuilder(context, new OutletVisitNoteEnvelopeBuilder(context))))); return new Transactor(database).Transact(() => { envelopeBuilder.Build().ForEach(e => envelopeRouter.RouteCommandEnvelope(e)); sale.OrderReference = context.OrderSaleReference(); sale.ConfirmNewPayments(); sale.ProcessingStatus = ProcessingStatus.Submitted; saleRepository.Save(sale); }); }
public void Execute(Envelope envelope, IEnvelopeContext context) { try { context.SendOutgoingMessages(envelope, _context.OutgoingMessages()); envelope.Callback.MarkSuccessful(); var message = new MessageSuccessful { Envelope = envelope.ToToken() }; if (!message.Envelope.IsDelayedEnvelopePollingJobRelated()) context.InfoMessage(message); } catch (Exception ex) { context.SendFailureAcknowledgement(envelope, "Sending cascading message failed: " + ex.Message); context.Error(envelope.CorrelationId, ex.Message, ex); envelope.Callback.MoveToErrors(new ErrorReport(envelope, ex)); } }
public Result<object> Process(Sale sale, IEnvelopeContext context) { var envelopeBuilder = new DeliveryEnvelopeBuilder(sale, new CloseOrderEnvelopeBuilder(context, new DispatchNoteEnvelopeBuilder(context, new PaymentNoteEnvelopeBuilder(context, new ReceiptEnvelopeBuilder(context, new CreditNoteEnvelopeBuilder(context, new InventoryAdjustmentNoteEnvelopeBuilder(context, inventoryRepository, new OutletVisitNoteEnvelopeBuilder(context)))))))); return new Transactor(database).Transact(() => { envelopeBuilder.Build().ForEach(e => envelopeRouter.RouteCommandEnvelope(e)); sale.ConfirmNewPayments(); sale.ProcessingStatus = sale.HasNoBackorderItems ? ProcessingStatus.Confirmed : ProcessingStatus.PartiallyFulfilled; saleRepository.Save(sale); }); }
public async Task Execute(Envelope envelope, IEnvelopeContext context, DateTime utcNow) { try { await context.SendAllQueuedOutgoingMessages(); await envelope.Callback.MarkComplete(); context.Logger.MessageSucceeded(envelope); } catch (Exception ex) { await context.SendFailureAcknowledgement(envelope, "Sending cascading message failed: " + ex.Message); context.Logger.LogException(ex, envelope.Id, ex.Message); context.Logger.MessageFailed(envelope, ex); await envelope.Callback.MoveToErrors(envelope, ex); } }
public Task Execute(Envelope envelope, IEnvelopeContext context, DateTime utcNow) { try { context.SendAllQueuedOutgoingMessages(); envelope.Callback.MarkSuccessful(); context.Logger.MessageSucceeded(envelope); } catch (Exception ex) { context.SendFailureAcknowledgement(envelope, "Sending cascading message failed: " + ex.Message); context.Logger.LogException(ex, envelope.CorrelationId, ex.Message); context.Logger.MessageFailed(envelope, ex); envelope.Callback.MoveToErrors(new ErrorReport(envelope, ex)); } return(Task.CompletedTask); }
public void Execute(Envelope envelope, IEnvelopeContext context) { try { context.SendOutgoingMessages(envelope, _context.OutgoingMessages()); envelope.Callback.MarkSuccessful(); var message = new MessageSuccessful { Envelope = envelope.ToToken() }; if (!message.Envelope.IsDelayedEnvelopePollingJobRelated()) { context.InfoMessage(message); } } catch (Exception ex) { context.SendFailureAcknowledgement(envelope, "Sending cascading message failed: " + ex.Message); context.Error(envelope.CorrelationId, ex.Message, ex); envelope.Callback.MoveToErrors(new ErrorReport(envelope, ex)); } }
public Result<object> Process(Sale sale, IEnvelopeContext context) { var envelopeBuilder = new SaleEnvelopeBuilder(sale, new MainOrderEnvelopeBuilder(context, new CloseOrderEnvelopeBuilder(context, new ExternalDocRefEnvelopeBuilder(context, new DispatchNoteEnvelopeBuilder(context, new InvoiceEnvelopeBuilder(context, new PaymentNoteEnvelopeBuilder(context, new ReceiptEnvelopeBuilder(context, new InventoryAdjustmentNoteEnvelopeBuilder(context, inventoryRepository, new OutletVisitNoteEnvelopeBuilder(context)))))))))); return new Transactor(database).Transact(() => { envelopeBuilder.Build().ForEach(e => envelopeRouter.RouteCommandEnvelope(e)); inventoryRepository.AdjustInventoryForSale(sale); sale.OrderReference = context.OrderSaleReference(); sale.ConfirmNewPayments(); sale.ProcessingStatus = ProcessingStatus.Confirmed; saleRepository.Save(sale); }); }
public void Execute(Envelope envelope, IEnvelopeContext context) { throw new NotImplementedException(); }
public ReceiptEnvelopeBuilder(IEnvelopeContext context, IEnvelopeBuilder linkedBuilder) : base(context, linkedBuilder) { }
public ReceiptEnvelopeBuilder(IEnvelopeContext context) : base(context) { }
public CloseOrderEnvelopeBuilder(IEnvelopeContext context, IEnvelopeBuilder linkedBuilder) : base(context, linkedBuilder) { }
public InvoiceEnvelopeBuilder(IEnvelopeContext context) : base(context) { DocumentId = Context.InvoiceId; }
public Task Execute(Envelope envelope, IEnvelopeContext context, DateTime utcNow) { context.SendOutgoingMessage(envelope, Message); return(Task.CompletedTask); }
public OutletVisitNoteEnvelopeBuilder(IEnvelopeContext context, IEnvelopeBuilder linkedBuilder) : base(context, linkedBuilder) { DocumentId = Context.VisitId; }
public static void AssertCommonEnvelopeChecks(List<CommandEnvelope> envelopes, IEnvelopeContext context) { Console.WriteLine(JsonConvert.SerializeObject(envelopes, Formatting.Indented)); Assert.AreEqual(1, envelopes.Count, "Envelope count"); CheckEnvelopeReferences(envelopes, context); var documentCommands = ExtractDocumentCommands(envelopes); CheckDocumentCommandReferences(documentCommands, envelopes[0], context); }
public static void CheckDocumentCommandReferences(List<DocumentCommand> documentCommands, CommandEnvelope commandEnvelope, IEnvelopeContext context) { documentCommands.ForEach(c => { Assert.AreEqual(commandEnvelope.ParentDocumentId, c.PDCommandId, "PDCommandId in command {0}", c.CommandTypeRef); Assert.AreEqual(commandEnvelope.DocumentId, c.DocumentId, "DocumentId in command {0}", c.CommandTypeRef); Assert.AreEqual(context.GeneratedByUserId, c.CommandGeneratedByUserId, "GeneratedByUserId in command {0}", c.CommandTypeRef); Assert.AreEqual(context.GeneratedByCostCentreId, c.CommandGeneratedByCostCentreId, "CommandGeneratedByCostCentreId in command {0}", c.CommandTypeRef); Assert.AreEqual(context.GeneratedByCostCentreApplicationId, c.CommandGeneratedByCostCentreApplicationId, "CommandGeneratedByCostCentreApplicationId in command {0}", c.CommandTypeRef); var createCommand = c as CreateCommand; if (createCommand != null) { Assert.AreEqual(context.GeneratedByCostCentreId, createCommand.DocumentIssuerCostCentreId, "DocumentIssuerCostCentreId in command {0}", c.CommandTypeRef); Assert.AreEqual(context.GeneratedByUserId, createCommand.DocIssuerUserId, "DocIssuerUserId in command {0}", c.CommandTypeRef); } }); }
public static void CheckEnvelopeReferences(List<CommandEnvelope> envelopes, IEnvelopeContext context) { envelopes.ForEach( e => { var type = (DocumentType) e.DocumentTypeId; Assert.AreEqual(context.GeneratedByCostCentreApplicationId, e.GeneratedByCostCentreApplicationId, "GeneratedByCostCentreApplicationId in message {0}", type); Assert.AreEqual(context.GeneratedByCostCentreId, e.GeneratedByCostCentreId, "GeneratedByCostCentreId in message {0}", type); Assert.AreEqual(context.ParentDocumentId, e.ParentDocumentId, "ParentDocumentId in message {0}", type); }); }
public Task Execute(Envelope envelope, IEnvelopeContext context, DateTime utcNow) { return(envelope.Callback.Requeue(envelope)); }
public void Invoke(Envelope envelope, IEnvelopeContext context) { Invoked.Add(envelope); }
public Task Execute(Envelope envelope, IEnvelopeContext context, DateTime utcNow) { return(context.Retry(envelope)); }
public Task Invoke(Envelope envelope, IEnvelopeContext context) { Invoked.Add(envelope); return(Task.CompletedTask); }
public override void Execute(Envelope envelope, IEnvelopeContext context) { envelope.Callback.MarkSuccessful(); }
public OutletVisitNoteEnvelopeBuilder(IEnvelopeContext context) : base(context) { DocumentId = Context.VisitId; }
public CreditNoteEnvelopeBuilder(IEnvelopeContext context) : base(context) { }
public InvoiceEnvelopeBuilder(IEnvelopeContext context, IEnvelopeBuilder linkedBuilder) : base(context, linkedBuilder) { DocumentId = Context.InvoiceId; }
public abstract void Execute(Envelope envelope, IEnvelopeContext context);
public override void Execute(Envelope envelope, IEnvelopeContext context) { context.SendFailureAcknowledgement(envelope, "No subscriber"); envelope.Callback.MarkSuccessful(); context.InfoMessage(() => new NoHandlerForMessage{Envelope = envelope.ToToken()}); }
public Task Execute(Envelope envelope, IEnvelopeContext context, DateTime utcNow) { // TODO -- should the callback stuff be async too? envelope.Callback.Requeue(envelope); return(Task.CompletedTask); }
public CreditNoteEnvelopeBuilder(IEnvelopeContext context, IEnvelopeBuilder linkedBuilder) : base(context, linkedBuilder) { }
public void Execute(Envelope envelope, IEnvelopeContext context) { ++Counter; }
public void Execute(Envelope envelope, IEnvelopeContext context) { context.SendOutgoingMessages(envelope, new[] { Message }); }
public void Execute(Envelope envelope, IEnvelopeContext context) { envelope.Callback.MoveToDelayedUntil(context.SystemTime.UtcNow().Add(_delay)); }
public OrderAndContext(Sale order, IEnvelopeContext context) { Sale = order; Context = context; }
public CloseOrderEnvelopeBuilder(IEnvelopeContext context) : base(context) { }
public Task Execute(Envelope envelope, IEnvelopeContext context, DateTime utcNow) { return(envelope.Callback.MoveToScheduledUntil(utcNow.Add(Delay), envelope)); }