-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Initialize router separate from Starting - Do not drop unrecognized messages silently
- Loading branch information
1 parent
1c82320
commit 8a7951f
Showing
13 changed files
with
214 additions
and
37 deletions.
There are no files selected for viewing
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
25 changes: 24 additions & 1 deletion
25
src/AcceptanceTesting/TestTransport/TestTransportQueueCreator.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 |
---|---|---|
@@ -1,10 +1,33 @@ | ||
namespace NServiceBus | ||
{ | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Transport; | ||
|
||
class TestTransportQueueCreator : ICreateQueues | ||
{ | ||
public Task CreateQueueIfNecessary(QueueBindings queueBindings, string identity) => Task.CompletedTask; | ||
readonly string storagePath; | ||
|
||
public TestTransportQueueCreator(string storagePath) | ||
{ | ||
this.storagePath = storagePath; | ||
} | ||
|
||
public Task CreateQueueIfNecessary(QueueBindings queueBindings, string identity) | ||
{ | ||
foreach (var queueBinding in queueBindings.ReceivingAddresses) | ||
{ | ||
var queuePath = Path.Combine(storagePath, queueBinding); | ||
Directory.CreateDirectory(queuePath); | ||
} | ||
|
||
foreach (var queueBinding in queueBindings.SendingAddresses) | ||
{ | ||
var queuePath = Path.Combine(storagePath, queueBinding); | ||
Directory.CreateDirectory(queuePath); | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
...Router.AcceptanceTests/SingleRouter/When_intentionally_dropping_messages_in_prerouting.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,87 @@ | ||
using System.Threading.Tasks; | ||
using NServiceBus.AcceptanceTesting; | ||
using NServiceBus.AcceptanceTests; | ||
using NServiceBus.AcceptanceTests.EndpointTemplates; | ||
using NUnit.Framework; | ||
|
||
namespace NServiceBus.Router.AcceptanceTests.SingleRouter | ||
{ | ||
using System; | ||
using Pipeline; | ||
|
||
[TestFixture] | ||
public class When_intentionally_dropping_messages_in_prerouting : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public async Task Should_not_complain() | ||
{ | ||
var result = await Scenario.Define<Context>() | ||
.WithRouter("Router", (ctx, cfg) => | ||
{ | ||
cfg.AddInterface<TestTransport>("Left", t => t.BrokerAlpha()).InMemorySubscriptions(); | ||
cfg.AddInterface<TestTransport>("Right", t => t.BrokerBravo()).InMemorySubscriptions(); | ||
|
||
cfg.UseStaticRoutingProtocol().AddForwardRoute("Left", "Right"); | ||
cfg.AddRule(_ => new DropMessagesRule(ctx)); | ||
}) | ||
.WithEndpoint<Sender>(c => c.When(s => s.Send(new MyRequest()))) | ||
.Done(c => c.Dropped) | ||
.Run(TimeSpan.FromSeconds(20)); | ||
|
||
Assert.IsTrue(result.Dropped); | ||
} | ||
|
||
class DropMessagesRule : IRule<PreroutingContext, PreroutingContext> | ||
{ | ||
Context scenarioContext; | ||
|
||
public DropMessagesRule(Context scenarioContext) | ||
{ | ||
this.scenarioContext = scenarioContext; | ||
} | ||
|
||
public async Task Invoke(PreroutingContext context, Func<PreroutingContext, Task> next) | ||
{ | ||
context.DoNotRequireThisMessageToBeForwarded(); | ||
await next(context); | ||
scenarioContext.Dropped = true; | ||
} | ||
} | ||
|
||
class Context : ScenarioContext | ||
{ | ||
public bool Dropped { get; set; } | ||
} | ||
|
||
class Sender : EndpointConfigurationBuilder | ||
{ | ||
public Sender() | ||
{ | ||
EndpointSetup<DefaultServer>(c => | ||
{ | ||
var routing = c.UseTransport<TestTransport>().BrokerAlpha().Routing(); | ||
var router = routing.ConnectToRouter("Router"); | ||
router.DelegateRouting(typeof(MyRequest)); | ||
c.Pipeline.Register(new RemoveIntentBehavior(), "Remove message intent header"); | ||
}); | ||
} | ||
|
||
class RemoveIntentBehavior : Behavior<IDispatchContext> | ||
{ | ||
public override Task Invoke(IDispatchContext context, Func<Task> next) | ||
{ | ||
foreach (var operation in context.Operations) | ||
{ | ||
operation.Message.Headers.Remove(Headers.MessageIntent); | ||
} | ||
|
||
return next(); | ||
} | ||
} | ||
} | ||
|
||
class MyRequest : IMessage | ||
{ | ||
} | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
src/NServiceBus.Router/Pipeline/Prerouting/PreroutingTerminator.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,14 @@ | ||
using System.Threading.Tasks; | ||
using NServiceBus.Router; | ||
|
||
class PreroutingTerminator : ChainTerminator<PreroutingContext> | ||
{ | ||
protected override Task<bool> Terminate(PreroutingContext context) | ||
{ | ||
if (!context.Dropped && !context.Forwarded) | ||
{ | ||
throw new UnforwardableMessageException($"The incoming message {context.MessageId} has not been forwarded. This might indicate a configuration problem."); | ||
} | ||
return Task.FromResult(true); | ||
} | ||
} |
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
11 changes: 6 additions & 5 deletions
11
src/NServiceBus.Router/Pipeline/Prerouting/PreroutingToReplyPreroutingFork.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
11 changes: 6 additions & 5 deletions
11
src/NServiceBus.Router/Pipeline/Prerouting/PreroutingToSendPreroutingFork.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
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
Oops, something went wrong.