You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
9.8 KiB
9.8 KiB
Webhooks管理模块
**本文档引用的文件** - [WebhookSubscriptionAppService.cs](file://aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application/LINGYUN/Abp/WebhooksManagement/WebhookSubscriptionAppService.cs) - [WebhookSubscriptionManager.cs](file://aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookSubscriptionManager.cs) - [WebhookSubscriptionsStore.cs](file://aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/WebhookSubscriptionsStore.cs) - [WebhookDefinitionManager.cs](file://aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/WebhookDefinitionManager.cs) - [WebhooksEventHandler.cs](file://aspnet-core/services/LY.MicroService.WebhooksManagement.HttpApi.Host/EventBus/Handlers/WebhooksEventHandler.cs) - [WebhookSubscriptionInfo.cs](file://aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookSubscriptionInfo.cs) - [WebhookEvent.cs](file://aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/WebhookEvent.cs) - [WebhookSubscriptionEto.cs](file://aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain.Shared/LINGYUN/Abp/WebhooksManagement/WebhookSubscriptionEto.cs)目录
简介
Webhooks管理模块为系统提供了事件驱动的外部通知机制。该模块允许租户订阅特定的系统事件,并配置回调URL来接收这些事件的通知。模块实现了完整的CRUD操作、安全性验证、重试机制和错误处理,支持多租户环境下的事件发布/订阅模型。
项目结构
Webhooks管理模块采用分层架构设计,包含多个独立的组件,每个组件负责特定的功能领域。模块遵循ABP框架的模块化设计原则,确保了高内聚低耦合的特性。
graph TB
subgraph "Webhooks模块"
subgraph "应用层"
AppService[WebhookSubscriptionAppService]
Dto[DTOs]
end
subgraph "领域层"
Domain[WebhookSubscription]
Repository[IWebhookSubscriptionRepository]
Store[WebhookSubscriptionsStore]
end
subgraph "核心层"
Core[WebhookDefinitionManager]
Manager[WebhookSubscriptionManager]
Event[WebhookEvent]
end
subgraph "基础设施"
EF[EntityFrameworkCore]
StoreImpl[WebhookSubscriptionsStore实现]
end
AppService --> Repository
Repository --> Store
Store --> EF
AppService --> Core
Manager --> Store
Core --> StoreImpl
end
图表来源
- WebhookSubscriptionAppService.cs
- WebhookSubscriptionsStore.cs
- WebhookDefinitionManager.cs
章节来源
- WebhookSubscriptionAppService.cs
- WebhookSubscriptionsStore.cs
核心组件
Webhooks管理模块的核心组件包括订阅管理、事件发布、安全性验证和消息序列化。这些组件协同工作,确保事件能够可靠地从系统内部传递到外部系统。
章节来源
- WebhookSubscriptionManager.cs
- WebhookDefinitionManager.cs
架构概述
Webhooks管理模块采用事件驱动架构,通过分布式事件总线接收系统事件,然后根据订阅关系将事件转发到外部系统的回调URL。模块实现了完整的发布/订阅模式,支持多租户和权限控制。
sequenceDiagram
participant EventBus as 事件总线
participant Handler as WebhooksEventHandler
participant Manager as WebhookSubscriptionManager
participant Store as WebhookSubscriptionsStore
participant Job as BackgroundJobManager
participant External as 外部系统
EventBus->>Handler : 发布WebhooksEventData
Handler->>Manager : 获取订阅列表
Manager->>Store : 查询活动订阅
Store-->>Manager : 返回订阅信息
Manager-->>Handler : 返回订阅列表
Handler->>Handler : 保存Webhook事件
Handler->>Job : 排队Webhook发送任务
Job-->>External : 发送HTTP请求
External-->>Job : 返回响应
Job->>Job : 处理重试或完成
图表来源
- WebhooksEventHandler.cs
- WebhookSubscriptionManager.cs
- WebhookSubscriptionsStore.cs
详细组件分析
订阅管理分析
Webhooks订阅管理组件负责处理Webhook订阅的CRUD操作,包括创建、读取、更新和删除订阅。组件实现了完整的权限验证和数据一致性保证。
订阅管理类图
classDiagram
class WebhookSubscriptionAppService {
+IWebhookDefinitionManager WebhookDefinitionManager
+IWebhookSubscriptionRepository SubscriptionRepository
+CreateAsync(input) WebhookSubscriptionDto
+GetAsync(id) WebhookSubscriptionDto
+GetListAsync(input) PagedResultDto
+UpdateAsync(id, input) WebhookSubscriptionDto
+DeleteAsync(id) void
+GetAllAvailableWebhooksAsync() ListResultDto
}
class WebhookSubscriptionManager {
+IWebhookSubscriptionsStore WebhookSubscriptionsStore
+GetAsync(id) WebhookSubscriptionInfo
+GetAllSubscriptionsAsync(tenantId) List
+GetAllSubscriptionsIfFeaturesGrantedAsync(tenantId, webhookName) List
+IsSubscribedAsync(tenantId, webhookName) bool
+AddOrUpdateSubscriptionAsync(subscription) void
+ActivateWebhookSubscriptionAsync(id, active) void
+DeleteSubscriptionAsync(id) void
+AddWebhookAsync(subscription, webhookName) void
}
class WebhookSubscriptionsStore {
+IWebhookSubscriptionRepository SubscriptionRepository
+DeleteAsync(id) void
+GetAllSubscriptionsAsync(tenantId) List
+GetAllSubscriptionsAsync(tenantId, webhookName) List
+GetAllSubscriptionsOfTenantsAsync(tenantIds) List
+GetAsync(id) WebhookSubscriptionInfo
+InsertAsync(subscription) void
+UpdateAsync(subscription) void
+IsSubscribedAsync(tenantId, webhookName) bool
}
WebhookSubscriptionAppService --> WebhookSubscriptionManager : "依赖"
WebhookSubscriptionManager --> WebhookSubscriptionsStore : "使用"
WebhookSubscriptionsStore --> IWebhookSubscriptionRepository : "使用"
图表来源
- WebhookSubscriptionAppService.cs
- WebhookSubscriptionManager.cs
- WebhookSubscriptionsStore.cs
章节来源
- WebhookSubscriptionAppService.cs
- WebhookSubscriptionManager.cs
事件发布分析
事件发布组件负责处理系统事件的发布和分发,确保订阅了特定事件的外部系统能够及时收到通知。组件实现了可靠的消息传递机制,包括重试和错误处理。
事件发布序列图
sequenceDiagram
participant Publisher as 事件发布者
participant EventBus as 分布式事件总线
participant Handler as WebhooksEventHandler
participant Manager as WebhookSubscriptionManager
participant Job as BackgroundJobManager
participant External as 外部系统
Publisher->>EventBus : 发布WebhooksEventData
EventBus->>Handler : 触发HandleEventAsync
Handler->>Manager : GetAllSubscriptionsOfTenantsIfFeaturesGrantedAsync
Manager-->>Handler : 返回订阅列表
Handler->>Handler : SaveAndGetWebhookAsync
Handler->>Job : EnqueueAsync(WebhookSenderArgs)
loop 每个订阅
Job->>External : 发送HTTP POST请求
alt 成功
External-->>Job : 200 OK
Job->>Job : 标记为成功
else 失败
Job->>Job : 记录失败并计划重试
end
end
图表来源
- WebhooksEventHandler.cs
- WebhookSubscriptionManager.cs
章节来源
- WebhooksEventHandler.cs
消息序列化分析
消息序列化组件负责处理Webhook事件数据的序列化和反序列化,确保消息格式的一致性和兼容性。组件使用JSON格式作为消息的序列化格式。
消息序列化类图
classDiagram
class WebhookEvent {
+Guid Id
+string WebhookName
+string Data
+DateTime CreationTime
+Guid? TenantId