1
0
mirror of synced 2024-11-16 14:53:50 +00:00
Tapeti/Test/MarcoController.cs

95 lines
2.1 KiB
C#
Raw Normal View History

using System.Threading.Tasks;
2016-12-07 09:19:16 +00:00
using Tapeti;
using Tapeti.Annotations;
using Tapeti.Saga;
2016-12-07 09:19:16 +00:00
namespace Test
{
[DynamicQueue]
public class MarcoController : MessageController
{
private readonly IPublisher publisher;
private readonly ISagaProvider sagaProvider;
2016-12-07 09:19:16 +00:00
public MarcoController(IPublisher publisher, ISagaProvider sagaProvider)
2016-12-07 09:19:16 +00:00
{
this.publisher = publisher;
this.sagaProvider = sagaProvider;
2016-12-07 09:19:16 +00:00
}
/*
* For simple request response patterns, the return type can also be used:
public async Task<PoloMessage> Marco(MarcoMessage message, Visualizer visualizer)
2016-12-07 09:19:16 +00:00
{
visualizer.VisualizeMarco();
return new PoloMessage(); ;
}
*/
// Visualizer can also be constructor injected, just proving a point here...
public async Task Marco(MarcoMessage message, Visualizer visualizer)
{
visualizer.VisualizeMarco();
2016-12-07 09:19:16 +00:00
using (var saga = await sagaProvider.Begin(new MarcoPoloSaga()))
{
// TODO provide publish extension with Saga support
await publisher.Publish(new PoloMessage(), saga);
2016-12-07 09:19:16 +00:00
}
}
2016-12-07 09:19:16 +00:00
public void Polo(PoloMessage message, Visualizer visualizer, ISaga<MarcoPoloSaga> saga)
{
if (saga.State.ReceivedPolo)
return;
saga.State.ReceivedPolo = true;
visualizer.VisualizePolo();
2016-12-07 09:19:16 +00:00
}
/*
[CallID("eerste")]
Implicit:
using (sagaProvider.Continue(correlatieID))
{
saga refcount--;
public void PoloColorResponse1(PoloColorResponse message, ISaga<MarcoState> saga)
{
saga.State == MarcoState
state.Color = message.Color;
if (state.Complete)
{
publisher.Publish(new PoloMessage());
}
}
*/
}
public class MarcoMessage
{
}
public class PoloMessage
{
}
public class MarcoPoloSaga
2016-12-07 09:19:16 +00:00
{
public bool ReceivedPolo;
2016-12-07 09:19:16 +00:00
}
}