1
0
mirror of synced 2024-11-22 01:13:49 +00:00
Tapeti/Examples/02-DeclareDurableQueues/Program.cs

48 lines
1.3 KiB
C#
Raw Normal View History

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()
{
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();
2022-02-09 08:19:56 +00:00
await dependencyResolver.Resolve<IPublisher>().Publish(new PublishSubscribeMessage
{
Greeting = "Hello durable queue!"
});
2022-02-09 08:19:56 +00:00
// Wait for the controller to signal that the message has been received
await waitForDone();
}
}
}