I'll start with the basics.
I am creating an app and want to split it out to microservices. Because I want the microservices to run when the computer is turned on, in the background, regardless of anyone being logged into the computer, I am creating 4 Windows services.
I can create a service just fine. The issue is I want a publish/subscribe method to handle events between the services. I do NOT want a command -> reply method as I want the services to only care about doing their thing and notifying any subscriber when event happens. They shouldn't block anything or care who is subscribed.
Everything I found says RabbitMQ is great for this exact situation. Hence why I am asking about it.
But I can't find anything that provides a simple explanation on how to use RabbitMQ to implement event notifications between multiple Windows services. I found lots of things that show how to use RabbitMQ in a web app but I am not creating a web app.
For an example, one event would be MapUpdated. Another service would need to know when a MapUpdated event happens but does not need to imediatly perform an action. Aka, a que is fine and a command/reply is not needed.
The below service runs fine. But it has no idea about events.
public sealed class WindowsBackgroundService(
DownloadService downloadService,
ILogger<WindowsBackgroundService> logger) : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
try
{
if (!stoppingToken.IsCancellationRequested)
{
await downloadService.DownloadInfoAsync(stoppingToken);
}
}
catch (OperationCanceledException)
{
}
catch (Exception ex)
{
logger.LogError(ex, "{Message}", ex.Message);
Environment.Exit(1);
}
}
}
How do I use RabbitMQ to allow this to download only when MapUpdated event happens (because that's when it should care)?