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

90 lines
3.5 KiB
C#
Raw Normal View History

using System;
using SimpleInjector;
using Tapeti;
2017-02-12 20:43:30 +00:00
using Tapeti.DataAnnotations;
using Tapeti.Flow;
using Tapeti.SimpleInjector;
using System.Threading;
using Tapeti.Transient;
namespace Test
{
internal class Program
{
private static void Main()
{
// TODO logging
//try
2019-01-24 21:52:21 +00:00
{
var container = new Container();
container.Register<MarcoEmitter>();
container.Register<Visualizer>();
container.Register<ILogger, Tapeti.Default.ConsoleLogger>();
2018-06-12 08:12:52 +00:00
2019-01-24 21:52:21 +00:00
var config = new TapetiConfig(new SimpleInjectorDependencyResolver(container))
//.WithFlowSqlRepository("Server=localhost;Database=TapetiTest;Integrated Security=true")
.WithFlow()
.WithDataAnnotations()
.WithTransient(TimeSpan.FromSeconds(30))
.EnableDeclareDurableQueues()
2019-01-24 21:52:21 +00:00
.RegisterAllControllers()
//.DisablePublisherConfirms() -> you probably never want to do this if you're using Flow or want requeues when a publish fails
.Build();
2019-01-24 21:52:21 +00:00
using (var connection = new TapetiConnection(config)
{
Params = new TapetiAppSettingsConnectionParams()
})
{
var flowStore = container.GetInstance<IFlowStore>();
var flowStore2 = container.GetInstance<IFlowStore>();
Console.WriteLine("IFlowHandler is singleton = " + (flowStore == flowStore2));
flowStore.Load().Wait();
2019-01-24 21:52:21 +00:00
connection.Connected += (sender, e) => { Console.WriteLine("Event Connected"); };
connection.Disconnected += (sender, e) => { Console.WriteLine("Event Disconnected"); };
connection.Reconnected += (sender, e) => { Console.WriteLine("Event Reconnected"); };
2019-01-24 21:52:21 +00:00
Console.WriteLine("Subscribing...");
var subscriber = connection.Subscribe(false).Result;
2019-01-24 21:52:21 +00:00
Console.WriteLine("Consuming...");
subscriber.Resume().Wait();
2019-01-24 21:52:21 +00:00
Console.WriteLine("Done!");
/*
var response = container.GetInstance<ITransientPublisher>()
.RequestResponse<PoloConfirmationRequestMessage, PoloConfirmationResponseMessage>(
new PoloConfirmationRequestMessage
{
StoredInState = new Guid("309088d8-9906-4ef3-bc64-56976538d3ab")
}).Result;
Console.WriteLine(response.ShouldMatchState);
*/
//connection.GetPublisher().Publish(new FlowEndController.PingMessage());
container.GetInstance<IFlowStarter>().Start<MarcoController, bool>(c => c.StartFlow, true).Wait();
container.GetInstance<IFlowStarter>().Start<MarcoController>(c => c.TestParallelRequest).Wait();
2019-01-24 21:52:21 +00:00
Thread.Sleep(1000);
//var emitter = container.GetInstance<MarcoEmitter>();
//emitter.Run().Wait();
Console.WriteLine("Press any Enter to continue");
Console.ReadLine();
2019-01-24 21:52:21 +00:00
}
}
//catch (Exception e)
2019-01-24 21:52:21 +00:00
{
// Console.WriteLine(e.ToString());
// Console.ReadKey();
}
}
}
}