protected override TransportOperations CreateMessage(MyContext context) { var messageId = Guid.NewGuid().ToString(); context.UniqueId = DeterministicGuid.MakeId(messageId, "Error.SourceEndpoint").ToString(); return new TransportOperations(GetMessages(context.UniqueId).ToArray()); }
public async Task Handle(HeartbeatingEndpointDetected domainEvent) { var endpoint = domainEvent.Endpoint; var id = DeterministicGuid.MakeId(endpoint.Name, endpoint.HostId.ToString()); using (var session = store.OpenAsyncSession()) { var knownEndpoint = await session.LoadAsync <KnownEndpoint>(id) .ConfigureAwait(false); if (knownEndpoint == null) { knownEndpoint = new KnownEndpoint { Id = id, EndpointDetails = endpoint, HostDisplayName = endpoint.Host, Monitored = true }; await session.StoreAsync(knownEndpoint).ConfigureAwait(false); } else { knownEndpoint.Monitored = monitoring.IsMonitored(id); } await session.SaveChangesAsync() .ConfigureAwait(false); } }
protected override TransportOperations CreateMessage(MyContext context) { context.EndpointNameOfReceivingEndpoint = Conventions.EndpointNamingConvention(typeof(Failing)); context.MessageId = Guid.NewGuid().ToString(); context.UniqueMessageId = DeterministicGuid.MakeId(context.MessageId, context.EndpointNameOfReceivingEndpoint).ToString(); var headers = new Dictionary <string, string> { [Headers.MessageId] = context.MessageId, [Headers.ProcessingEndpoint] = context.EndpointNameOfReceivingEndpoint, ["NServiceBus.ExceptionInfo.ExceptionType"] = "2014-11-11 02:26:57:767462 Z", ["NServiceBus.ExceptionInfo.Message"] = "An error occurred while attempting to extract logical messages from transport message NServiceBus.TransportMessage", ["NServiceBus.ExceptionInfo.InnerExceptionType"] = "System.Exception", ["NServiceBus.ExceptionInfo.Source"] = "NServiceBus.Core", ["NServiceBus.ExceptionInfo.StackTrace"] = String.Empty, ["NServiceBus.FailedQ"] = Conventions.EndpointNamingConvention(typeof(Failing)), ["NServiceBus.TimeOfFailure"] = "2014-11-11 02:26:58:000462 Z" }; if (context.TimeSent.HasValue) { headers["NServiceBus.TimeSent"] = DateTimeExtensions.ToWireFormattedString(context.TimeSent.Value); } var outgoingMessage = new OutgoingMessage(context.MessageId, headers, new byte[0]); return(new TransportOperations( new TransportOperation(outgoingMessage, new UnicastAddressTag("error")) )); }
public async Task Handle(MonitoringEnabledForEndpoint domainEvent) { var id = DeterministicGuid.MakeId(domainEvent.Endpoint.Name, domainEvent.Endpoint.HostId.ToString()); using (var session = store.OpenAsyncSession()) { var knownEndpoint = await session.LoadAsync <KnownEndpoint>(id) .ConfigureAwait(false); if (knownEndpoint == null) { knownEndpoint = new KnownEndpoint { Id = id, EndpointDetails = domainEvent.Endpoint, HostDisplayName = domainEvent.Endpoint.Host }; await session.StoreAsync(knownEndpoint).ConfigureAwait(false); } knownEndpoint.Monitored = true; await session.SaveChangesAsync() .ConfigureAwait(false); } }
protected override TransportOperations CreateMessage(MyContext context) { context.EndpointNameOfReceivingEndpoint = Conventions.EndpointNamingConvention(typeof(FailureEndpoint)); context.MessageId = Guid.NewGuid().ToString(); context.UniqueMessageId = DeterministicGuid.MakeId(context.MessageId, context.EndpointNameOfReceivingEndpoint).ToString(); var headers = new Dictionary <string, string> { [Headers.MessageId] = context.MessageId, [Headers.ProcessingEndpoint] = context.EndpointNameOfReceivingEndpoint, ["NServiceBus.ExceptionInfo.ExceptionType"] = "2014-11-11 02:26:57:767462 Z", ["NServiceBus.ExceptionInfo.Message"] = "An error occurred while attempting to extract logical messages from transport message NServiceBus.TransportMessage", ["NServiceBus.ExceptionInfo.InnerExceptionType"] = "System.Exception", ["NServiceBus.ExceptionInfo.Source"] = "NServiceBus.Core", ["NServiceBus.ExceptionInfo.StackTrace"] = String.Empty, ["NServiceBus.FailedQ"] = Conventions.EndpointNamingConvention(typeof(FailureEndpoint)), ["NServiceBus.TimeOfFailure"] = "2014-11-11 02:26:58:000462 Z", [Headers.ControlMessageHeader] = Boolean.TrueString, ["NServiceBus.ClearTimeouts"] = Boolean.TrueString, ["NServiceBus.SagaId"] = "626f86be-084c-4867-a5fc-a53f0092b299" }; var outgoingMessage = new OutgoingMessage(context.MessageId, headers, new byte[0]); return(new TransportOperations(new TransportOperation(outgoingMessage, new UnicastAddressTag("error")))); }
public void Handle(FailingMessage message) { TestContext.ProcessingAttemptCount++; Console.WriteLine($"Handling message {Bus.CurrentMessageContext.Id} attempt {TestContext.ProcessingAttemptCount}"); if (Bus.CurrentMessageContext.Headers.ContainsKey(TestContext.HeaderKey)) { Console.WriteLine($"Retrying message {Bus.CurrentMessageContext.Id}"); TestContext.RetryUniqueMessageId = Bus.CurrentMessageContext.Headers[TestContext.HeaderKey]; TestContext.Retried = true; } else if (TestContext.ProcessingAttemptCount == 1) { TestContext.MessageId = Bus.CurrentMessageContext.Id; TestContext.ReplyToAddress = Bus.CurrentMessageContext.ReplyToAddress.ToString(); TestContext.UniqueMessageId = DeterministicGuid.MakeId(Bus.CurrentMessageContext.Id, Settings.LocalAddress().Queue).ToString(); } if (TestContext.Retried && TestContext.HasSuccessInTheEnd) { return; } throw new Exception("Simulated Exception"); }
public async Task Should_be_successfully_deleted() { var redirect = new RedirectRequest { fromphysicaladdress = "endpointA@machine1", tophysicaladdress = "endpointB@machine2" }; var response = new List<MessageRedirectFromJson>(); var messageRedirectId = DeterministicGuid.MakeId(redirect.fromphysicaladdress); await Define<Context>() .Done(async ctx => { await this.Post("/api/redirects", redirect); await this.Delete($"/api/redirects/{messageRedirectId}/"); var result = await this.TryGetMany<MessageRedirectFromJson>("/api/redirects"); response = result; return true; }) .Run(); Assert.AreEqual(0, response.Count, "Expected no redirects after delete"); }
public static Negotiator WithDeterministicEtag(this Negotiator negotiator, string data, Etag ravenEtag = null) { var guid = DeterministicGuid.MakeId(data, (ravenEtag ?? Etag.Empty).ToString(), false); return(negotiator .WithHeader("ETag", guid.ToString())); }
public async Task Should_be_added_and_accessible_via_the_api() { var redirect = new RedirectRequest { fromphysicaladdress = "endpointA@machine1", tophysicaladdress = "endpointB@machine2" }; var response = new List <MessageRedirectFromJson>(); await Define <Context>() .Done(async ctx => { await this.Post("/api/redirects", redirect); var result = await this.TryGetMany <MessageRedirectFromJson>("/api/redirects"); response = result; return(result); }).Run(); Assert.AreEqual(1, response.Count, "Expected 1 redirect to be created"); Assert.AreEqual(DeterministicGuid.MakeId(redirect.fromphysicaladdress), response[0].message_redirect_id, "Message Redirect Id mismatch"); Assert.AreEqual(redirect.fromphysicaladdress, response[0].from_physical_address, "From physical address mismatch"); Assert.AreEqual(redirect.tophysicaladdress, response[0].to_physical_address, "To physical address mismatch"); Assert.Greater(response[0].last_modified, DateTime.MinValue, "Last modified was not set"); }
protected override TransportOperations CreateMessage(MyContext context) { context.DecommissionedEndpointName = "DecommissionedEndpointName"; context.DecommissionedEndpointMessageId = Guid.NewGuid().ToString(); context.DecommissionedEndpointUniqueMessageId = DeterministicGuid.MakeId(context.DecommissionedEndpointMessageId, context.DecommissionedEndpointName).ToString(); var headers = new Dictionary <string, string> { [Headers.MessageId] = context.DecommissionedEndpointMessageId, ["NServiceBus.ExceptionInfo.ExceptionType"] = "2014-11-11 02:26:57:767462 Z", ["NServiceBus.ExceptionInfo.Message"] = "An error occurred while attempting to extract logical messages from transport message NServiceBus.TransportMessage", ["NServiceBus.ExceptionInfo.InnerExceptionType"] = "System.Exception", ["NServiceBus.ExceptionInfo.Source"] = "NServiceBus.Core", ["NServiceBus.ExceptionInfo.StackTrace"] = string.Empty, [Headers.ProcessingEndpoint] = context.DecommissionedEndpointName, ["NServiceBus.FailedQ"] = context.DecommissionedEndpointName, ["NServiceBus.TimeOfFailure"] = "2014-11-11 02:26:58:000462 Z" }; var outgoingMessage = new OutgoingMessage(context.DecommissionedEndpointMessageId, headers, new byte[0]); return(new TransportOperations( new TransportOperation(outgoingMessage, new UnicastAddressTag("error")) )); }
public EndpointInstanceId(string logicalName, string hostName, Guid hostGuid) { LogicalName = logicalName; HostName = hostName; HostGuid = hostGuid; UniqueId = DeterministicGuid.MakeId(LogicalName, HostGuid.ToString()); }
public async Task Should_return_conflict_when_it_will_create_a_dependency() { var updateRedirect = new RedirectRequest { fromphysicaladdress = "endpointA@machine1", tophysicaladdress = "endpointB@machine2" }; var conflictRedirect = new RedirectRequest { fromphysicaladdress = "endpointC@machine3", tophysicaladdress = "endpointD@machine4" }; var messageRedirectId = DeterministicGuid.MakeId(updateRedirect.fromphysicaladdress); await Define <Context>() .Done(async ctx => { await this.Post("/api/redirects", updateRedirect); await this.Post("/api/redirects", conflictRedirect); await this.Put($"/api/redirects/{messageRedirectId}/", new { tophysicaladdress = conflictRedirect.fromphysicaladdress }, status => status != HttpStatusCode.Conflict); return(true); }).Run(); }
public void Start() { context.EndpointNameOfReceivingEndpoint = settings.EndpointName(); context.MessageId = Guid.NewGuid().ToString(); context.UniqueMessageId = DeterministicGuid.MakeId(context.MessageId, context.EndpointNameOfReceivingEndpoint).ToString(); var transportMessage = new TransportMessage(); transportMessage.Headers[Headers.ProcessingEndpoint] = context.EndpointNameOfReceivingEndpoint; transportMessage.Headers[Headers.MessageId] = context.MessageId; transportMessage.Headers[Headers.ConversationId] = "a59395ee-ec80-41a2-a728-a3df012fc707"; transportMessage.Headers["$.diagnostics.hostid"] = "bdd4b0510bff5a6d07e91baa7e16a804"; transportMessage.Headers["$.diagnostics.hostdisplayname"] = "SELENE"; transportMessage.Headers["NServiceBus.ExceptionInfo.ExceptionType"] = "2014-11-11 02:26:57:767462 Z"; transportMessage.Headers["NServiceBus.ExceptionInfo.Message"] = "An error occurred while attempting to extract logical messages from transport message NServiceBus.TransportMessage"; transportMessage.Headers["NServiceBus.ExceptionInfo.InnerExceptionType"] = "System.Exception"; transportMessage.Headers["NServiceBus.ExceptionInfo.HelpLink"] = String.Empty; transportMessage.Headers["NServiceBus.ExceptionInfo.Source"] = "NServiceBus.Core"; transportMessage.Headers["NServiceBus.ExceptionInfo.StackTrace"] = String.Empty; transportMessage.Headers["NServiceBus.FailedQ"] = settings.LocalAddress().ToString(); transportMessage.Headers["NServiceBus.TimeOfFailure"] = "2014-11-11 02:26:58:000462 Z"; transportMessage.Headers["NServiceBus.TimeSent"] = "2014-11-11 02:26:01:174786 Z"; transportMessage.Headers[Headers.ControlMessageHeader] = Boolean.TrueString; transportMessage.Headers[Headers.ReplyToAddress] = settings.LocalAddress().ToString(); sendMessages.Send(transportMessage, new SendOptions(Address.Parse("error"))); }
public async Task <ProcessedMessage> ConvertToSaveMessage(MessageContext message) { if (!message.Headers.TryGetValue(Headers.MessageId, out var messageId)) { messageId = DeterministicGuid.MakeId(message.MessageId).ToString(); } var metadata = new ConcurrentDictionary <string, object> { ["MessageId"] = messageId, ["MessageIntent"] = message.Headers.MessageIntent(), }; var enricherTasks = new List <Task>(enrichers.Length); // ReSharper disable once LoopCanBeConvertedToQuery foreach (var enricher in enrichers) { enricherTasks.Add(enricher.Enrich(message.Headers, metadata)); } await Task.WhenAll(enricherTasks) .ConfigureAwait(false); await bodyStorageEnricher.StoreAuditMessageBody(message.Body, message.Headers, metadata) .ConfigureAwait(false); var auditMessage = new ProcessedMessage(message.Headers, new Dictionary <string, object>(metadata)) { // We do this so Raven does not spend time assigning a hilo key Id = $"ProcessedMessages/{Guid.NewGuid()}" }; return(auditMessage); }
protected override TransportOperations CreateMessage(MyContext context) { context.EndpointNameOfReceivingEndpoint = Conventions.EndpointNamingConvention(typeof(FailureEndpoint)); context.MessageId = Guid.NewGuid().ToString(); context.UniqueMessageId = DeterministicGuid.MakeId(context.MessageId, context.EndpointNameOfReceivingEndpoint).ToString(); var headers = new Dictionary <string, string> { [Headers.ProcessingEndpoint] = context.EndpointNameOfReceivingEndpoint, [Headers.MessageId] = context.MessageId, [Headers.ConversationId] = "a59395ee-ec80-41a2-a728-a3df012fc707", ["$.diagnostics.hostid"] = "bdd4b0510bff5a6d07e91baa7e16a804", ["$.diagnostics.hostdisplayname"] = "SELENE", ["NServiceBus.ExceptionInfo.ExceptionType"] = "2014-11-11 02:26:57:767462 Z", ["NServiceBus.ExceptionInfo.Message"] = "An error occurred while attempting to extract logical messages from transport message NServiceBus.TransportMessage", ["NServiceBus.ExceptionInfo.InnerExceptionType"] = "System.Exception", ["NServiceBus.ExceptionInfo.HelpLink"] = String.Empty, ["NServiceBus.ExceptionInfo.Source"] = "NServiceBus.Core", ["NServiceBus.ExceptionInfo.StackTrace"] = String.Empty, ["NServiceBus.FailedQ"] = Conventions.EndpointNamingConvention(typeof(FailureEndpoint)), ["NServiceBus.TimeOfFailure"] = "2014-11-11 02:26:58:000462 Z", ["NServiceBus.TimeSent"] = "2014-11-11 02:26:01:174786 Z", [Headers.ControlMessageHeader] = Boolean.TrueString, [Headers.ReplyToAddress] = Conventions.EndpointNamingConvention(typeof(FailureEndpoint)) }; var outgoingMessage = new OutgoingMessage(context.MessageId, headers, new byte[0]); return(new TransportOperations( new TransportOperation(outgoingMessage, new UnicastAddressTag("error")) )); }
public static string UniqueId(this IReadOnlyDictionary <string, string> headers) { string existingUniqueMessageId; return(headers.TryGetValue("ServiceControl.Retry.UniqueMessageId", out existingUniqueMessageId) ? existingUniqueMessageId : DeterministicGuid.MakeId(headers.MessageId(), headers.ProcessingEndpointName()).ToString()); }
public void Handle(EndpointHeartbeatRestored message) { var id = DeterministicGuid.MakeId(message.Endpoint.Name, message.Endpoint.HostId.ToString()); Bus.SendLocal(new EnableEndpointMonitoring { EndpointId = id }); }
public void Handle(MessageThatWillFail message) { if (!Context.ExceptionThrown) //simulate that the exception will be resolved with the retry { Context.UniqueMessageId = DeterministicGuid.MakeId(Bus.CurrentMessageContext.Id.Replace(@"\", "-"), Settings.LocalAddress().Queue).ToString(); Context.ExceptionThrown = Context.IssueRetry = true; throw new Exception("Simulated exception"); } Context.Done = true; }
public static HttpResponseMessage WithDeterministicEtag(this HttpResponseMessage response, string data) { if (string.IsNullOrEmpty(data)) { return(response); } var guid = DeterministicGuid.MakeId(data); return(response.WithEtag(Etag.Parse(guid.ToString()))); }
public Task Handle(MessageThatWillFail message, IMessageHandlerContext context) { if (!Context.ExceptionThrown) //simulate that the exception will be resolved with the retry { Context.UniqueMessageId = DeterministicGuid.MakeId(context.MessageId, Settings.EndpointName()).ToString(); Context.ExceptionThrown = Context.IssueRetry = true; throw new Exception("Simulated exception"); } Context.Done = true; return(Task.FromResult(0)); }
public void Handle(OriginalMessage message) { var messageId = Bus.CurrentMessageContext.Id.Replace(@"\", "-"); Context.UniqueMessageId = DeterministicGuid.MakeId(messageId, Settings.LocalAddress().Queue).ToString(); if (!Context.RetryIssued) { throw new Exception("This is still the original attempt"); } Bus.Reply(new ReplyMessage()); }
public static Negotiator WithDeterministicEtag(this Negotiator negotiator, string data) { if (string.IsNullOrEmpty(data)) { return(negotiator); } var guid = DeterministicGuid.MakeId(data); return(negotiator .WithHeader("ETag", guid.ToString())); }
public async Task SubsequentBatchesShouldBeProcessed() { FailedMessage decomissionedFailure = null, successfullyRetried = null; CustomConfiguration = config => { config.RegisterComponents(components => components.ConfigureComponent(b => new ReturnToSenderDequeuer(b.Build <IBodyStorage>(), new SendMessagesWrapper(b.Build <ISendMessages>(), b.Build <MyContext>()), b.Build <IDocumentStore>(), b.Build <IDomainEvents>(), b.Build <Configure>()), DependencyLifecycle.SingleInstance)); }; await Define <MyContext>() .WithEndpoint <FailureEndpoint>(b => b.Given((bus, ctx) => { ctx.DecommissionedEndpointName = "DecommissionedEndpoint"; ctx.DecommissionedEndpointMessageId = Guid.NewGuid().ToString(); ctx.DecommissionedEndpointUniqueMessageId = DeterministicGuid.MakeId(ctx.DecommissionedEndpointMessageId, ctx.DecommissionedEndpointName).ToString(); }) .When(async ctx => { return(!ctx.RetryForInvalidAddressIssued && await TryGetSingle <FailedMessage>("/api/errors/", m => m.Id == ctx.DecommissionedEndpointUniqueMessageId)); }, async(bus, ctx) => { await Post <object>($"/api/errors/{ctx.DecommissionedEndpointUniqueMessageId}/retry"); bus.SendLocal(new MessageThatWillFail()); ctx.RetryForInvalidAddressIssued = true; }) .When(async ctx => { return(!ctx.RetryForMessageThatWillFailAndThenBeResolvedIssued && await TryGetSingle <FailedMessage>("/api/errors/", m => m.Id == ctx.MessageThatWillFailUniqueMessageId)); }, async(bus, ctx) => { await Post <object>($"/api/errors/{ctx.MessageThatWillFailUniqueMessageId}/retry"); ctx.RetryForMessageThatWillFailAndThenBeResolvedIssued = true; })) .Done(async ctx => { if (!ctx.Done) { return(false); } var decomissionedFailureResult = await TryGetSingle <FailedMessage>("/api/errors/", m => m.Id == ctx.DecommissionedEndpointUniqueMessageId && m.Status == FailedMessageStatus.Unresolved); decomissionedFailure = decomissionedFailureResult; var successfullyRetriedResult = await TryGetSingle <FailedMessage>("/api/errors/", m => m.Id == ctx.MessageThatWillFailUniqueMessageId && m.Status == FailedMessageStatus.Resolved); successfullyRetried = successfullyRetriedResult; return(decomissionedFailureResult && successfullyRetriedResult); }) .Run(TimeSpan.FromMinutes(3)); Assert.NotNull(decomissionedFailure); Assert.NotNull(successfullyRetried); Assert.AreEqual(FailedMessageStatus.Unresolved, decomissionedFailure.Status); Assert.AreEqual(FailedMessageStatus.Resolved, successfullyRetried.Status); }
public Task Handle(FailingMessage message, IMessageHandlerContext context) { if (message.HasBeenEdited) { testContext.EditedMessageFailureId = DeterministicGuid.MakeId(context.MessageId, settings.EndpointName()).ToString(); } else { testContext.OriginalMessageFailureId = DeterministicGuid.MakeId(context.MessageId, settings.EndpointName()).ToString(); } throw new SimulatedException(); }
public PreSplitScenario(FailedMessageStatus originalStatus) { UniqueMessageId = DeterministicGuid.MakeId(MessageId, ReplyToAddress).ToString(); OriginalFailedMessageStatus = originalStatus; FailedMessage = new FailedMessage() { Id = FailedMessage.MakeDocumentId(UniqueMessageId), UniqueMessageId = UniqueMessageId, ProcessingAttempts = new List <FailedMessage.ProcessingAttempt>(), Status = originalStatus, FailureGroups = new List <FailedMessage.FailureGroup>() }; }
public void Handle(MyMessage message) { Console.WriteLine("Message Handled"); if (Context.AboutToSendRetry) { Context.Retried = true; } else { Context.UniqueMessageId = DeterministicGuid.MakeId(Bus.CurrentMessageContext.Id.Replace(@"\", "-"), Settings.LocalAddress().Queue).ToString(); throw new Exception("Simulated Exception"); } }
public void Handle(MyMessage message) { var messageId = Bus.CurrentMessageContext.Id.Replace(@"\", "-"); TestContext.UniqueMessageId = DeterministicGuid.MakeId(messageId, Settings.LocalAddress().Queue).ToString(); if (!TestContext.RetryIssued) { throw new Exception("Simulated exception"); } TestContext.RetryHandled = true; }
protected override TransportOperations CreateMessage(MyContext context) { var messageId = Guid.NewGuid().ToString(); context.UniqueId = DeterministicGuid.MakeId(messageId, "Error.SourceEndpoint").ToString(); context.FailureTimes = new[] { new DateTime(2020, 09, 05, 13, 20, 00, 0, DateTimeKind.Utc), new DateTime(2020, 09, 05, 12, 20, 00, 0, DateTimeKind.Utc), }; return(new TransportOperations(GetMessages(context.UniqueId, context.FailureTimes).ToArray())); }
public Task Handle(EditMessage message, IMessageHandlerContext context) { if (!testContext.EditedMessage) { var messageId = context.MessageId.Replace(@"\", "-"); testContext.UniqueMessageId = DeterministicGuid.MakeId(messageId, settings.EndpointName()).ToString(); testContext.OriginalMessageId = context.MessageId; throw new SimulatedException("message body needs to be changed"); } testContext.EditedMessageHeaders = context.MessageHeaders.ToDictionary(kvp => kvp.Key, kvp => kvp.Value); testContext.EditedMessageId = context.MessageId; return(Task.CompletedTask); }
public Task Handle(MyMessage message, IMessageHandlerContext context) { Console.WriteLine("Message Handled"); if (Context.Step == 0) { Context.FromAddress = Settings.LocalAddress(); Context.UniqueMessageId = DeterministicGuid.MakeId(context.MessageId, Settings.EndpointName()).ToString(); throw new Exception("Simulated Exception"); } Context.RetryCount++; Context.Retried = true; return(Task.FromResult(0)); }