-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #410 from Particular/error-queue-8-1
Move poisonous messages to the error queue
- Loading branch information
Showing
6 changed files
with
121 additions
and
6 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
src/AcceptanceTests/CustomEndpointConfigurationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace NServiceBus.AcceptanceTests | ||
{ | ||
using Configuration.AdvancedExtensibility; | ||
|
||
public static class CustomEndpointConfigurationExtensions | ||
{ | ||
public static TransportExtensions<AzureStorageQueueTransport> ConfigureAsqTransport(this EndpointConfiguration configuration) | ||
{ | ||
return new TransportExtensions<AzureStorageQueueTransport>(configuration.GetSettings()); | ||
} | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
src/AcceptanceTests/Receiving/When_MessageReceived_fails_to_unwrap_a_message.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
namespace NServiceBus.Azure.Transports.WindowsAzureStorageQueues.AcceptanceTests.Receiving | ||
{ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using AcceptanceTesting; | ||
using NServiceBus.AcceptanceTests; | ||
using NServiceBus.AcceptanceTests.EndpointTemplates; | ||
using NUnit.Framework; | ||
|
||
public class When_MessageReceived_fails_to_unwrap_a_message : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public async Task Should_move_message_to_the_error_queue() | ||
{ | ||
var context = await Scenario.Define<Context>() | ||
.WithEndpoint<Receiver>(b => | ||
{ | ||
b.When(async (e, c) => | ||
{ | ||
var message = new MyMessage | ||
{ | ||
Id = c.TestRunId | ||
}; | ||
|
||
await e.SendLocal(message); | ||
}); | ||
}) | ||
.WithEndpoint<ErrorSpy>() | ||
.Done(c => c.MessageMovedToErrorQueue) | ||
.Run(); | ||
|
||
var exceptionThrownByUnwrapper = context.Logs.Any(x => x.Message.StartsWith("Failed to deserialize message envelope for message with id")); | ||
Assert.That(exceptionThrownByUnwrapper, "Exception thrown by MessageRetrieved.Unwrap() was expected but wasn't found"); | ||
} | ||
|
||
class Context : ScenarioContext | ||
{ | ||
public bool GotMessage { get; set; } | ||
public bool MessageMovedToErrorQueue { get; set; } | ||
} | ||
|
||
class Receiver : EndpointConfigurationBuilder | ||
{ | ||
public Receiver() | ||
{ | ||
EndpointSetup<DefaultServer>(config => | ||
{ | ||
config.SendFailedMessagesTo(AcceptanceTesting.Customization.Conventions.EndpointNamingConvention(typeof(ErrorSpy))); | ||
config.UseSerialization<NewtonsoftSerializer>(); | ||
config.LimitMessageProcessingConcurrencyTo(1); | ||
var transport = config.ConfigureAsqTransport(); | ||
transport.UnwrapMessagesWith(message => throw new Exception("Custom unwrapper failed")); | ||
transport.DelayedDelivery().DisableDelayedDelivery(); | ||
}); | ||
} | ||
} | ||
|
||
class ErrorSpy : EndpointConfigurationBuilder | ||
{ | ||
public ErrorSpy() | ||
{ | ||
EndpointSetup<DefaultServer>(config => | ||
{ | ||
var transport = config.ConfigureAsqTransport(); | ||
config.UseSerialization<NewtonsoftSerializer>(); | ||
transport.DelayedDelivery().DisableDelayedDelivery(); | ||
}); | ||
} | ||
|
||
class MyMessageHandler : IHandleMessages<MyMessage> | ||
{ | ||
readonly Context testContext; | ||
|
||
public MyMessageHandler(Context testContext) | ||
{ | ||
this.testContext = testContext; | ||
} | ||
|
||
public Task Handle(MyMessage message, IMessageHandlerContext context) | ||
{ | ||
if (message.Id == testContext.TestRunId) | ||
{ | ||
testContext.MessageMovedToErrorQueue = true; | ||
} | ||
|
||
return Task.FromResult(0); | ||
} | ||
} | ||
} | ||
|
||
public class MyMessage : IMessage | ||
{ | ||
public Guid Id { get; set; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Weavers> | ||
<Weavers GenerateXsd="false"> | ||
<Obsolete /> | ||
<Janitor /> | ||
</Weavers> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters