Implementing worker microservices with ASP.NET Core
In order to avoid blocking the caller’s synchronous request for too much time, an ASP.NET Core-based solution requires the implementation of an internal queue where it can store all received messages. This way, when a message is received, it is immediately enqueued without processing it, so that a “received” response can be immediately returned.
Therefore, the application level needs a repository interface that handles the queue. Here is a possible definition of this interface:
public interface IMessageQueue
{
public Task<IList<QueueItem>> Top(int n);
public Task Dequeue(IEnumerable<QueueItem> items);
public Task Enqueue(QueueItem item);
}
Where:
QueueItem
is a class that contains all request informationEnqueue
adds a new message to the queueTop
returns the firstn
queue items without removing them from the queueDequeue
removes the first...