Microservice Solution: Background Workers
You must have an ABP Business or a higher license to be able to create a microservice solution.
Background workers are long-running processes that perform tasks in the background. They are used in microservice systems to handle tasks that run continuously or periodically, such as data processing, notifications, and more. The ABP Framework includes a system for creating and running these workers in your application. You can learn more in the Background Workers document.
Basically, you can create scheduled workers for a specific time interval based on your requirements, such as checking the status of inactive users and changing their status to passive if they have not logged in to the application in the last 30 days.
After creating a worker, we should also register it in the related microservice or project. You can register your worker in the OnApplicationInitializationAsync
method of your module class.
An important point in distributed systems is that the same background workers could be running in multiple instances of the same service. So, you should be careful about the side effects of the workers. For example, if you are processing a message from a queue, you should ensure that the message is processed only once. You can use distributed locking to prevent multiple instances from processing the same message. You can find more information about distributed locking in microservice environments in the distributed locking document.