0

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)?

3
  • See if following helps : stackoverflow.com/questions/24309230/… Commented Jul 20 at 22:19
  • I highly recommend you to NOT use any popular message broker if your intent is to only provide a way of communication between services on same machine. Use any SQL compatible broker and abstract away from publishing/subscribing behind interface. Hangfire will do the job just fine. Commented Jul 20 at 22:25
  • Hangfire is a job que. How do I tell it to fire an event in another service? The point of microservices is that they don't know anything about other services so telling Hangfire to queue a job for a specific service kinda defeats the purpose, unless hangfire allows me specify an event name instead of a callback method... Commented Jul 21 at 1:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.