![]() |
VOOZH | about |
dotnet add package Galosys.Foundation.Yarp.Database --version 26.5.19.1
NuGet\Install-Package Galosys.Foundation.Yarp.Database -Version 26.5.19.1
<PackageReference Include="Galosys.Foundation.Yarp.Database" Version="26.5.19.1" />
<PackageVersion Include="Galosys.Foundation.Yarp.Database" Version="26.5.19.1" />Directory.Packages.props
<PackageReference Include="Galosys.Foundation.Yarp.Database" />Project file
paket add Galosys.Foundation.Yarp.Database --version 26.5.19.1
#r "nuget: Galosys.Foundation.Yarp.Database, 26.5.19.1"
#:package Galosys.Foundation.Yarp.Database@26.5.19.1
#addin nuget:?package=Galosys.Foundation.Yarp.Database&version=26.5.19.1Install as a Cake Addin
#tool nuget:?package=Galosys.Foundation.Yarp.Database&version=26.5.19.1Install as a Cake Tool
基于 EntityFrameworkCore 的 YARP 网关数据库持久化模块,提供路由模板管理和对接日志批量写入。
成熟度: 🟡 可用 — 功能完整,测试或文档可能不完善
dotnet add package Galosys.Foundation.Yarp.Database
builder.Services.AddYarpCore(builder.Environment);
builder.Services.AddYarbConfigProvider<DatabaseYarpConfigProvider>(); // 数据库配置
引入此模块后,DockingLog 日志将通过独立 BoundedChannel + BackgroundService 批量写入数据库,不再通过全局事件总线逐条写入。
路由模板自动应用 Gateway:Ha 高可用配置(健康检查、超时),详见 Galosys.Foundation.Yarp 模块 README。每条路由可通过 activity_timeout 字段覆盖默认超时。
DockingLogBatchConsumer(BackgroundService)从独立 BoundedChannel<DockingLog> 消费日志BatchSize 条(默认 200)或超过 BatchIntervalMs(默认 500ms)db.AddRangeAsync(batch) + db.SaveChangesAsync()DropOldest(丢弃最旧日志,不阻塞网关转发)批量写入参数通过 Gateway:Metric 配置节控制,详见 Galosys.Foundation.Yarp 模块 README。
DockingLog 实体的 EFCore 映射已从 Data Annotations 迁移到 Fluent API,由 DockingLogEntityTypeConfiguration 统一管理:
// 位于 Microsoft/EntityFrameworkCore/Metadata/Builders/DockingLogEntityTypeConfiguration.cs
// 继承 EntityTypeConfigurationBase<DockingLog, long>,自动获得:
// - snake_case 列名映射(无需手动 [Column] 标注)
// - TenantAppEntity 的复合索引(TenantId + AppId)
// - ICreator/ILastModifier 的字段长度约束
// 额外配置:
builder.ToTable("docking_log", "base"); // 表名 + Schema
builder.HasIndex(e => e.OccurredOn); // 事件时间索引
builder.HasIndex(e => e.ClusterId); // 集群标识索引
builder.HasIndex(e => new { e.OccurredOn, e.ClusterId }); // 复合索引
自动发现机制: DockingCenterDbContext 继承 DbContext<T>,OnModelCreating 通过 DependencyContext.Default.GetTypes() 扫描所有已加载程序集中的 IEntityTypeConfiguration<> 实现,自动应用配置。无需手动在 DbContext 中注册或重写 OnModelCreating。
此模式可作为跨模块使用 EntityTypeConfigurationBase 的示范——即使实体定义在 Galosys.Foundation.Yarp,配置类定义在 Galosys.Foundation.Yarp.Database,自动发现仍然生效。
CREATE TABLE docking_center.docking_log (
id bigint NOT NULL,
request_path varchar(64) NOT NULL, -- 请求路径
request_url varchar(64) NOT NULL, -- 请求完整 URL
request_method varchar(64) NULL, -- HTTP 方法
router_template_id bigint NULL, -- 关联路由模板 ID
execute_result bit DEFAULT 0 NOT NULL, -- 转发是否成功
occurred_on datetime2 NULL, -- 事件发生时间
status_code int DEFAULT 0 NOT NULL, -- HTTP 响应状态码
elapsed bigint DEFAULT 0 NOT NULL, -- 转发耗时(毫秒)
cluster_id varchar(64) NULL, -- YARP 目标集群标识
error_message varchar(2000) NULL, -- 转发错误信息
deleted bit DEFAULT 0 NOT NULL,
creator_id bigint DEFAULT 1 NULL,
creator_name varchar(64) DEFAULT '1' NOT NULL,
created_at datetime2 NOT NULL,
last_modifier_id bigint NULL,
last_modifier_name varchar(64) NULL,
last_modified_at datetime2 NULL,
tenant_id bigint NULL,
app_id bigint NULL,
CONSTRAINT PK_docking_center_docking_log PRIMARY KEY (id)
);
CREATE TABLE docking_center.router_template (
id bigint NOT NULL,
template_code varchar(64) NOT NULL,
request_path varchar(64) NOT NULL,
router_uri varchar(512) NULL,
path_prefix varchar(64) NULL,
path_remove_prefix varchar(64) NULL,
request_headers_copy bit DEFAULT 1 NOT NULL,
deleted bit DEFAULT 0 NOT NULL,
creator_id bigint DEFAULT 1 NULL,
creator_name varchar(64) DEFAULT '1' NOT NULL,
created_at datetime2 NOT NULL,
last_modifier_id bigint NULL,
last_modifier_name varchar(64) NULL,
last_modified_at datetime2 NULL,
remark varchar(128) NULL,
max_retries int DEFAULT 5 NOT NULL,
load_balancer varchar(64) NULL, -- 负载均衡策略(RoundRobin、LeastRequests 等)
activity_timeout int NULL, -- 请求超时毫秒数(NULL 时使用 Gateway:Ha:DefaultActivityTimeoutMs 默认值)
[source] varchar(255) NULL,
target varchar(255) NULL,
CONSTRAINT PK_docking_center_router_template PRIMARY KEY (id)
);
CREATE UNIQUE NONCLUSTERED INDEX UIDX_router_template_code
ON docking_center.router_template (template_code ASC);
router_template 表的 load_balancer 字段控制每条路由的负载均衡策略:
| 值 | 说明 |
|---|---|
NULL |
使用默认值 RoundRobin |
RoundRobin |
轮询(默认) |
LeastRequests |
最少请求 |
PowerOfTwoChoices |
二选一 |
| 其他 YARP 支持的策略 | 透传给 YARP |
router_template 表的 activity_timeout 字段控制每条路由的请求超时:
| 值 | 说明 |
|---|---|
NULL |
使用 Gateway:Ha:DefaultActivityTimeoutMs 默认值(30s) |
5000 |
该路由超时 5s |
60000 |
该路由超时 60s |
需同步更新数据库表结构:
ALTER TABLE docking_center.router_template ADD activity_timeout int NULL;
DockingLog 实体移除所有 [Column] 和 [Table] Data Annotations,改由 DockingLogEntityTypeConfiguration 使用 Fluent API 配置(表名 base.docking_log、列名 snake_case 自动映射、索引)。DockingCenterDbContext 通过 EntityTypeConfigurationBase 自动发现机制加载配置,无需手动注册。此变更对数据库表结构无影响,仅改变 EFCore 映射方式。DockingLog 实体移除了 request_body、response_body、request_headers、request_query_params 列,新增 status_code、elapsed、cluster_id、error_message 列。需同步更新数据库表结构。DockingLogCreateHandler(逐条写入)已替换为 DockingLogBatchConsumer(批量写入)。router_template 新增 load_balancer 字段,支持按路由配置负载均衡策略。需同步更新数据库表结构(ALTER TABLE docking_center.router_template ADD load_balancer varchar(64) NULL)。router_template 新增 activity_timeout 字段,支持按路由配置请求超时。路由自动应用 Gateway:Ha 高可用配置(健康检查、超时)。| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 26.5.19.1 | 100 | 5/19/2026 |
| 26.5.18.1 | 100 | 5/18/2026 |
| 26.5.15.1 | 92 | 5/15/2026 |
| 26.5.12.3 | 93 | 5/12/2026 |
| 26.4.27.1-rc1 | 97 | 4/26/2026 |
| 26.4.25.1-rc1 | 90 | 4/25/2026 |
| 26.4.22.2-rc7 | 94 | 4/22/2026 |
| 26.4.22.2-rc6 | 94 | 4/22/2026 |
| 26.4.22.2-rc4 | 84 | 4/22/2026 |
| 26.4.22.2-rc3 | 89 | 4/22/2026 |
| 26.4.12.8-rc1 | 98 | 4/12/2026 |
| 26.4.12.7-rc1 | 99 | 4/12/2026 |
| 26.1.30.1-rc1 | 115 | 1/30/2026 |
| 26.1.29.1 | 116 | 1/29/2026 |
| 26.1.28.5 | 113 | 1/28/2026 |
| 26.1.28.4 | 114 | 1/28/2026 |
| 26.1.28.2 | 114 | 1/28/2026 |
| 26.1.23.6 | 112 | 1/23/2026 |
| 26.1.21.1 | 114 | 1/21/2026 |
| 26.1.2.1 | 143 | 1/2/2026 |