2016-12-07 10:19:16 +01:00
|
|
|
|
using System;
|
2017-01-31 12:01:08 +01:00
|
|
|
|
using System.Threading.Tasks;
|
2016-12-07 10:19:16 +01:00
|
|
|
|
using Tapeti;
|
|
|
|
|
using Tapeti.Annotations;
|
2017-01-31 12:01:08 +01:00
|
|
|
|
using Tapeti.Flow;
|
|
|
|
|
using Tapeti.Flow.Annotations;
|
2016-12-07 10:19:16 +01:00
|
|
|
|
|
|
|
|
|
namespace Test
|
|
|
|
|
{
|
2017-02-08 15:52:24 +01:00
|
|
|
|
[MessageController]
|
2016-12-07 10:19:16 +01:00
|
|
|
|
[DynamicQueue]
|
2017-02-08 15:52:24 +01:00
|
|
|
|
public class MarcoController
|
2016-12-07 10:19:16 +01:00
|
|
|
|
{
|
|
|
|
|
private readonly IPublisher publisher;
|
2017-01-31 12:01:08 +01:00
|
|
|
|
private readonly IFlowProvider flowProvider;
|
|
|
|
|
private readonly Visualizer visualizer;
|
2016-12-07 10:19:16 +01:00
|
|
|
|
|
2017-01-31 12:01:08 +01:00
|
|
|
|
// Public properties are automatically stored and retrieved while in a flow
|
|
|
|
|
public Guid StateTestGuid;
|
2016-12-07 10:19:16 +01:00
|
|
|
|
|
2017-01-31 12:01:08 +01:00
|
|
|
|
|
|
|
|
|
public MarcoController(IPublisher publisher, IFlowProvider flowProvider, Visualizer visualizer)
|
2016-12-07 10:19:16 +01:00
|
|
|
|
{
|
|
|
|
|
this.publisher = publisher;
|
2017-01-31 12:01:08 +01:00
|
|
|
|
this.flowProvider = flowProvider;
|
|
|
|
|
this.visualizer = visualizer;
|
2016-12-07 10:19:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-01-31 12:01:08 +01:00
|
|
|
|
/**
|
|
|
|
|
* The Visualizer could've been injected through the constructor, which is
|
|
|
|
|
* the recommended way. Just testing the injection middleware here.
|
|
|
|
|
*/
|
2017-02-05 23:22:34 +01:00
|
|
|
|
public async Task<IYieldPoint> Marco(MarcoMessage message, Visualizer myVisualizer)
|
2016-12-07 10:19:16 +01:00
|
|
|
|
{
|
2017-02-05 23:22:34 +01:00
|
|
|
|
Console.WriteLine(">> Marco (yielding with request)");
|
2016-12-07 10:19:16 +01:00
|
|
|
|
|
2017-02-05 23:22:34 +01:00
|
|
|
|
await myVisualizer.VisualizeMarco();
|
2016-12-07 10:19:16 +01:00
|
|
|
|
|
2017-02-05 23:22:34 +01:00
|
|
|
|
return flowProvider.YieldWithRequestSync<PoloConfirmationRequestMessage, PoloConfirmationResponseMessage>(
|
2017-01-31 12:01:08 +01:00
|
|
|
|
new PoloConfirmationRequestMessage()
|
|
|
|
|
{
|
|
|
|
|
StoredInState = StateTestGuid
|
2017-02-05 23:22:34 +01:00
|
|
|
|
},
|
2017-01-31 12:01:08 +01:00
|
|
|
|
HandlePoloConfirmationResponse);
|
|
|
|
|
}
|
2016-12-07 10:19:16 +01:00
|
|
|
|
|
|
|
|
|
|
2017-02-05 23:22:34 +01:00
|
|
|
|
[Continuation]
|
|
|
|
|
public IYieldPoint HandlePoloConfirmationResponse(PoloConfirmationResponseMessage message)
|
2017-01-31 12:01:08 +01:00
|
|
|
|
{
|
2017-02-05 23:22:34 +01:00
|
|
|
|
Console.WriteLine(">> HandlePoloConfirmationResponse (ending flow)");
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(message.ShouldMatchState.Equals(StateTestGuid) ? "Confirmed!" : "Oops! Mismatch!");
|
|
|
|
|
|
|
|
|
|
return flowProvider.EndWithResponse(new PoloMessage());
|
2017-01-31 12:01:08 +01:00
|
|
|
|
}
|
2016-12-07 10:19:16 +01:00
|
|
|
|
|
|
|
|
|
|
2017-01-31 12:01:08 +01:00
|
|
|
|
/**
|
|
|
|
|
* For simple request response patterns, the return type can be used.
|
|
|
|
|
* This will automatically include the correlationId in the response and
|
|
|
|
|
* use the replyTo header of the request if provided.
|
|
|
|
|
*/
|
|
|
|
|
public PoloConfirmationResponseMessage PoloConfirmation(PoloConfirmationRequestMessage message)
|
2016-12-07 10:19:16 +01:00
|
|
|
|
{
|
2017-02-05 23:22:34 +01:00
|
|
|
|
Console.WriteLine(">> PoloConfirmation (returning confirmation)");
|
|
|
|
|
|
2017-01-31 12:01:08 +01:00
|
|
|
|
return new PoloConfirmationResponseMessage
|
|
|
|
|
{
|
|
|
|
|
ShouldMatchState = message.StoredInState
|
|
|
|
|
};
|
2016-12-07 10:19:16 +01:00
|
|
|
|
}
|
2017-02-05 23:22:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Polo(PoloMessage message)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(">> Polo");
|
|
|
|
|
StateTestGuid = Guid.NewGuid();
|
|
|
|
|
}
|
2016-12-07 10:19:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-02-05 23:22:34 +01:00
|
|
|
|
[Request(Response = typeof(PoloMessage))]
|
2016-12-07 10:19:16 +01:00
|
|
|
|
public class MarcoMessage
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class PoloMessage
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-01-31 12:01:08 +01:00
|
|
|
|
[Request(Response = typeof(PoloConfirmationResponseMessage))]
|
|
|
|
|
public class PoloConfirmationRequestMessage
|
2016-12-07 10:19:16 +01:00
|
|
|
|
{
|
2017-01-31 12:01:08 +01:00
|
|
|
|
public Guid StoredInState { get; set; }
|
2016-12-07 10:19:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-01-31 12:01:08 +01:00
|
|
|
|
public class PoloConfirmationResponseMessage
|
|
|
|
|
{
|
|
|
|
|
public Guid ShouldMatchState { get; set; }
|
2016-12-07 10:19:16 +01:00
|
|
|
|
}
|
|
|
|
|
}
|