ABP vNext + Dapr 实现云原生微服务治理 🚀
前言 📝
随着云原生与微服务架构的快速发展,相关工具和框架也在不断演进。ABP vNext 是一套成熟而现代的 .NET 应用开发框架,在模块化、领域驱动设计等方面提供强大支持。而 Dapr 作为一个轻量级、事件驱动的微服务运行时,提供服务发现、发布订阅、配置管理等能力,极大降低了构建分布式系统的复杂性。
本文将结合实际案例,介绍如何集成 ABP vNext 与 Dapr,实现服务间调用、配置集中管理、日志追踪、事件驱动等微服务治理能力。
一、环境搭建 🧰
技术栈
- 基础框架:ABP vNext (.NET 8)
- 微服务运行时:Dapr 1.13+
- 配置中心:Dapr Configuration API + Redis (推荐 Redis 6.0+)
- 服务调用:Dapr Service Invocation
- 链路追踪与日志:OpenTelemetry + Zipkin + Serilog
- 部署方式:Docker Compose
NuGet 包依赖(建议版本)
- Volo.Abp.Dapr (>=8.4.0)
- Dapr.AspNetCore (>=1.13.1)
- Dapr.Client
- Dapr.Extensions.Configuration
- OpenTelemetry.Exporter.Zipkin
- OpenTelemetry.Extensions.Hosting
- Serilog.AspNetCore
- StackExchange.Redis
二、初始化与模块注册 🔧
初始化与模块注册流程
1. 安装 Dapr CLI
wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash
dapr init
2. 创建 ABP 项目
abp new DaprMicroservice -t app --ui none
3. 注册 Dapr 模块依赖
[DependsOn(typeof(AbpDaprModule))]
public class OrderServiceModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.Configure<AbpDaprRemoteServiceOptions>(opt =>
{
opt.RemoteServices.Default.Protocol = "http";
opt.RemoteServices.Default.Address = "http://localhost:3500";
opt.RemoteServices.Default.DaprClientRetryPolicy = new DaprClientRetryPolicy
{
MaxRetryCount = 3,
Delay = TimeSpan.FromSeconds(2)
};
});
}
}

最低0.47元/天 解锁文章
3121

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



