2019-08-16 08:51:35 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using ExampleLib;
|
|
|
|
|
using Messaging.TapetiExample;
|
|
|
|
|
using SimpleInjector;
|
|
|
|
|
using Tapeti;
|
|
|
|
|
using Tapeti.Default;
|
|
|
|
|
using Tapeti.SimpleInjector;
|
|
|
|
|
|
|
|
|
|
namespace _02_DeclareDurableQueues
|
|
|
|
|
{
|
|
|
|
|
public class Program
|
|
|
|
|
{
|
2022-02-09 08:19:56 +00:00
|
|
|
|
public static void Main()
|
2019-08-16 08:51:35 +00:00
|
|
|
|
{
|
|
|
|
|
var container = new Container();
|
|
|
|
|
var dependencyResolver = new SimpleInjectorDependencyResolver(container);
|
|
|
|
|
|
|
|
|
|
container.Register<ILogger, ConsoleLogger>();
|
|
|
|
|
|
|
|
|
|
var helper = new ExampleConsoleApp(dependencyResolver);
|
|
|
|
|
helper.Run(MainAsync);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal static async Task MainAsync(IDependencyResolver dependencyResolver, Func<Task> waitForDone)
|
|
|
|
|
{
|
|
|
|
|
var config = new TapetiConfig(dependencyResolver)
|
|
|
|
|
.RegisterAllControllers()
|
|
|
|
|
.EnableDeclareDurableQueues()
|
|
|
|
|
.Build();
|
|
|
|
|
|
2022-02-09 08:19:56 +00:00
|
|
|
|
await using var connection = new TapetiConnection(config);
|
|
|
|
|
|
|
|
|
|
// This creates or updates the durable queue
|
|
|
|
|
await connection.Subscribe();
|
2019-08-16 08:51:35 +00:00
|
|
|
|
|
2022-02-09 08:19:56 +00:00
|
|
|
|
await dependencyResolver.Resolve<IPublisher>().Publish(new PublishSubscribeMessage
|
|
|
|
|
{
|
|
|
|
|
Greeting = "Hello durable queue!"
|
|
|
|
|
});
|
2019-08-16 08:51:35 +00:00
|
|
|
|
|
2022-02-09 08:19:56 +00:00
|
|
|
|
// Wait for the controller to signal that the message has been received
|
|
|
|
|
await waitForDone();
|
2019-08-16 08:51:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|