2016-12-14 19:28:17 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2016-12-07 09:19:16 +00:00
|
|
|
|
using Tapeti;
|
|
|
|
|
using Tapeti.Annotations;
|
2016-12-14 19:28:17 +00:00
|
|
|
|
using Tapeti.Saga;
|
2016-12-07 09:19:16 +00:00
|
|
|
|
|
|
|
|
|
namespace Test
|
|
|
|
|
{
|
|
|
|
|
[DynamicQueue]
|
|
|
|
|
public class MarcoController : MessageController
|
|
|
|
|
{
|
|
|
|
|
private readonly IPublisher publisher;
|
2016-12-14 19:28:17 +00:00
|
|
|
|
private readonly ISagaProvider sagaProvider;
|
2016-12-07 09:19:16 +00:00
|
|
|
|
|
|
|
|
|
|
2016-12-14 19:28:17 +00:00
|
|
|
|
public MarcoController(IPublisher publisher, ISagaProvider sagaProvider)
|
2016-12-07 09:19:16 +00:00
|
|
|
|
{
|
|
|
|
|
this.publisher = publisher;
|
2016-12-14 19:28:17 +00:00
|
|
|
|
this.sagaProvider = sagaProvider;
|
2016-12-07 09:19:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-12-14 19:28:17 +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
|
|
|
|
{
|
2016-12-13 21:01:43 +00:00
|
|
|
|
visualizer.VisualizeMarco();
|
2016-12-14 19:28:17 +00:00
|
|
|
|
return new PoloMessage(); ;
|
|
|
|
|
}
|
|
|
|
|
*/
|
2016-12-13 21:01:43 +00:00
|
|
|
|
|
2016-12-14 19:28:17 +00:00
|
|
|
|
// 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
|
|
|
|
|
2016-12-14 19:28:17 +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-14 19:28:17 +00:00
|
|
|
|
}
|
2016-12-07 09:19:16 +00:00
|
|
|
|
|
2016-12-14 19:28:17 +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
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-12-14 19:28:17 +00:00
|
|
|
|
public class MarcoPoloSaga
|
2016-12-07 09:19:16 +00:00
|
|
|
|
{
|
2016-12-14 19:28:17 +00:00
|
|
|
|
public bool ReceivedPolo;
|
2016-12-07 09:19:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|