微服务项目中的请求处理与测试实践
在微服务开发中,处理排队请求和测试代码是至关重要的环节。本文将详细介绍如何处理排队请求、如何使用假请求生成器测试项目,以及如何基于 RabbitMQ 构建微服务。
处理排队请求
实际的请求处理由与 ASP.NET Core 管道并行运行的工作主机服务执行。此服务使用泛型主机实现,以下是相关代码:
using GrpcMicroServiceStore;
using GrpcMicroServiceStore.Models;
namespace GrpcMicroService.HostedServices;
public class ProcessPurchases : BackgroundService
{
IServiceProvider services;
public ProcessPurchases(IServiceProvider services)
{
this.services = services;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
bool queueEmpty = false;
while (!stoppingToken.IsCancellationRequested)
{
while (!queueEmpty && !stoppingToken.IsCancellationRequested
超级会员免费看
订阅专栏 解锁全文
635

被折叠的 条评论
为什么被折叠?



