1
0
mirror of synced 2024-11-16 06:43:51 +00:00
Tapeti/Test/MarcoController.cs

98 lines
2.7 KiB
C#
Raw Normal View History

2016-12-07 09:19:16 +00:00
using System;
using System.Threading.Tasks;
2016-12-07 09:19:16 +00:00
using Tapeti;
using Tapeti.Annotations;
using Tapeti.Flow;
using Tapeti.Flow.Annotations;
2016-12-07 09:19:16 +00:00
namespace Test
{
[DynamicQueue]
public class MarcoController : MessageController
{
private readonly IPublisher publisher;
private readonly IFlowProvider flowProvider;
private readonly Visualizer visualizer;
2016-12-07 09:19:16 +00:00
// Public properties are automatically stored and retrieved while in a flow
public Guid StateTestGuid;
2016-12-07 09:19:16 +00:00
public MarcoController(IPublisher publisher, IFlowProvider flowProvider, Visualizer visualizer)
2016-12-07 09:19:16 +00:00
{
this.publisher = publisher;
this.flowProvider = flowProvider;
this.visualizer = visualizer;
2016-12-07 09:19:16 +00:00
}
/**
* The Visualizer could've been injected through the constructor, which is
* the recommended way. Just testing the injection middleware here.
*/
public async Task Marco(MarcoMessage message, Visualizer myVisualizer)
2016-12-07 09:19:16 +00:00
{
await myVisualizer.VisualizeMarco();
await publisher.Publish(new PoloMessage());
2016-12-07 09:19:16 +00:00
}
public IYieldPoint Polo(PoloMessage message)
2016-12-07 09:19:16 +00:00
{
StateTestGuid = Guid.NewGuid();
return flowProvider.YieldWithRequest<PoloConfirmationRequestMessage, PoloConfirmationResponseMessage>(
new PoloConfirmationRequestMessage()
{
StoredInState = StateTestGuid
},
HandlePoloConfirmationResponse);
}
2016-12-07 09:19:16 +00:00
public async Task<IYieldPoint> HandlePoloConfirmationResponse(PoloConfirmationResponseMessage message)
{
await visualizer.VisualizePolo(message.ShouldMatchState.Equals(StateTestGuid));
return flowProvider.End();
}
2016-12-07 09:19:16 +00: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.
*/
2016-12-07 09:19:16 +00:00
public PoloConfirmationResponseMessage PoloConfirmation(PoloConfirmationRequestMessage message)
2016-12-07 09:19:16 +00:00
{
return new PoloConfirmationResponseMessage
{
ShouldMatchState = message.StoredInState
};
2016-12-07 09:19:16 +00:00
}
}
public class MarcoMessage
{
}
public class PoloMessage
{
}
[Request(Response = typeof(PoloConfirmationResponseMessage))]
public class PoloConfirmationRequestMessage
2016-12-07 09:19:16 +00:00
{
public Guid StoredInState { get; set; }
2016-12-07 09:19:16 +00:00
}
public class PoloConfirmationResponseMessage
{
public Guid ShouldMatchState { get; set; }
2016-12-07 09:19:16 +00:00
}
}