Search code examples
c#.net-corerabbitmqmicroserviceskeep-alive

How to keep consumer app alive in .net core


I'm a having a bunch of simple asp.net core microservices which some of them don't get any HTTP request and just subscribe to a particular command (I'm using rabbitmq for this) so I want to reduce the extra headache of asp.net core and make them simple .net core console application, but the problem is that these console apps won't stay alive and simply die out after they reached the end of the main function scope so I want to know what is the best practice to keep these consumer console apps alive? Also it worth to mention that I want them for the production environment in Docker containers so simple infinite loop or a Console.ReadKey() wont work. Tnx


Solution

  • Once set up properly, calling start_consuming with your connection's channel will block the execution of your code. So, as long as you don't end it externally, the thread running this method won't exit and will be able to call your callback on each messages received.