-
Notifications
You must be signed in to change notification settings - Fork 647
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
122 additions
and
0 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
97 changes: 97 additions & 0 deletions
97
src/NServiceBus.AcceptanceTests/Sagas/When_using_ReplyToOriginator.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.AcceptanceTests.Sagas | ||
{ | ||
using System; | ||
using EndpointTemplates; | ||
using AcceptanceTesting; | ||
using NUnit.Framework; | ||
using Saga; | ||
|
||
public class When_using_ReplyToOriginator : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public void Should_set_Reply_as_messageintent() | ||
{ | ||
var context = new Context(); | ||
|
||
Scenario.Define(context) | ||
.WithEndpoint<Endpoint>(b => b.Given(bus => bus.SendLocal(new InitiateRequestingSaga()))) | ||
.Done(c => c.Done) | ||
.Run(); | ||
|
||
Assert.AreEqual(MessageIntentEnum.Reply, context.Intent); | ||
} | ||
|
||
public class Context : ScenarioContext | ||
{ | ||
public MessageIntentEnum Intent { get; set; } | ||
public bool Done { get; set; } | ||
} | ||
|
||
public class Endpoint : EndpointConfigurationBuilder | ||
{ | ||
|
||
public Endpoint() | ||
{ | ||
EndpointSetup<DefaultServer>(); | ||
} | ||
|
||
public class RequestingSaga : Saga<RequestingSaga.RequestingSagaData>, | ||
IAmStartedByMessages<InitiateRequestingSaga>, | ||
IHandleMessages<AnotherRequest> | ||
{ | ||
public Context Context { get; set; } | ||
|
||
public void Handle(InitiateRequestingSaga message) | ||
{ | ||
Data.CorrIdForResponse = Guid.NewGuid(); //wont be needed in the future | ||
|
||
Bus.SendLocal(new AnotherRequest | ||
{ | ||
SomeCorrelationId = Data.CorrIdForResponse //wont be needed in the future | ||
}); | ||
} | ||
|
||
public void Handle(AnotherRequest message) | ||
{ | ||
ReplyToOriginator(new MyReplyToOriginator()); | ||
MarkAsComplete(); | ||
} | ||
|
||
protected override void ConfigureHowToFindSaga(SagaPropertyMapper<RequestingSagaData> mapper) | ||
{ | ||
//if this line is un-commented the timeout and secondary handler tests will start to fail | ||
// for more info and discussion see TBD | ||
mapper.ConfigureMapping<AnotherRequest>(m => m.SomeCorrelationId).ToSaga(s => s.CorrIdForResponse); | ||
} | ||
public class RequestingSagaData : ContainSagaData | ||
{ | ||
public virtual Guid CorrIdForResponse { get; set; } //wont be needed in the future | ||
} | ||
} | ||
|
||
class MyReplyToOriginatorHandler : IHandleMessages<MyReplyToOriginator> | ||
{ | ||
public Context Context { get; set; } | ||
public IBus Bus { get; set; } | ||
|
||
public void Handle(MyReplyToOriginator message) | ||
{ | ||
Context.Intent = (MessageIntentEnum)Enum.Parse(typeof(MessageIntentEnum), Bus.CurrentMessageContext.Headers[Headers.MessageIntent]); | ||
Context.Done = true; | ||
} | ||
} | ||
} | ||
|
||
public class InitiateRequestingSaga : ICommand { } | ||
|
||
public class AnotherRequest : ICommand | ||
{ | ||
public Guid SomeCorrelationId { get; set; } | ||
} | ||
|
||
public class MyReplyToOriginator : IMessage | ||
{ | ||
public Guid SomeCorrelationId { 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
21 changes: 21 additions & 0 deletions
21
src/NServiceBus.Core/Unicast/Behaviors/FixSendIntentBehavior.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,21 @@ | ||
namespace NServiceBus | ||
{ | ||
using System; | ||
using NServiceBus.Pipeline; | ||
using NServiceBus.Pipeline.Contexts; | ||
|
||
class FixSendIntentBehavior : IBehavior<OutgoingContext> | ||
{ | ||
public void Invoke(OutgoingContext context, Action next) | ||
{ | ||
if (context.OutgoingLogicalMessage.Headers.ContainsKey("$.temporary.ReplyToOriginator")) | ||
{ | ||
context.OutgoingMessage.MessageIntent = MessageIntentEnum.Reply; | ||
context.OutgoingMessage.Headers.Remove("$.temporary.ReplyToOriginator"); | ||
context.OutgoingLogicalMessage.Headers.Remove("$.temporary.ReplyToOriginator"); | ||
} | ||
|
||
next(); | ||
} | ||
} | ||
} |