Chuyển tới nội dung chính

Tổng quan hệ thống Webhook

Webhook là gì?​

Hệ thống Webhook cho phép gửi HTTP POST request tới endpoint của tenant khi có sự kiện xảy ra trong hệ thống. Tenant cấu hình endpoint và phương thức xác thực; hệ thống tự động gửi và retry khi thất bại.

Luồng tổng quan​

Các thành phần chính​

1. TenantWebhook (Cấu hình webhook)​

Lưu cấu hình webhook của tenant: URL endpoint, mã định danh, timeout, chính sách retry, trạng thái và danh sách cấu hình auth.

  • Bảng: tenant_webhook
  • Ràng buộc duy nhất: (tenant_id, code)

2. TenantAuthConfig (Cấu hình xác thực)​

Lưu thông tin xác thực để gửi webhook: loại auth, giá trị (đã mã hóa) và vị trí áp dụng.

  • Bảng: tenant_auth_config
  • Hỗ trợ 3 loại: API_KEY, BASIC, HMAC

3. WebhookExecution (Theo dõi thực thi)​

Lưu chi tiết mỗi lần gửi webhook: URL, headers, request body, response, mã trạng thái HTTP, số lần retry, lỗi.

  • Bảng: webhook_execution

Các loại xác thực​

LoạiMô tả
API_KEYGửi API key trong header hoặc query parameter
BASICBase64 encode credentials, gửi trong header Authorization: Basic {base64}
HMACTính chữ ký từ payload bằng HMAC-SHA256, gửi trong header hoặc query

Chính sách retry​

PolicyMô tả
EXPONENTIAL_BACKOFFRetry 1: 60s, Retry 2: 120s, Retry 3+: 60s × (retryCount³)
IMMEDIATERetry sau 10s
  • Số lần retry tối đa: 3
  • Retry Worker chạy mỗi 2 phút, xử lý tối đa 100 execution mỗi lần
  • Dùng ShedLock để tránh trùng lặp trong cluster

Vòng đời Webhook Execution​

StatusGiá trịMô tả
RETRY_FAILED1Thất bại, chờ retry
SUCCESS2Gửi thành công
FAILED3Thất bại vĩnh viễn (hết retry)
RETRYING4Đang thực hiện retry

File chính liên quan​

FileĐường dẫnMô tả
WebhookServiceapplication/core/partner/webhook/WebhookService.javaInterface gửi webhook
WebhookServiceImplapplication/core/partner/webhook/impl/WebhookServiceImpl.javaLogic gửi webhook, áp dụng auth
WebhookExecutionServiceapplication/core/partner/webhook/WebhookExecutionService.javaInterface quản lý execution
WebhookExecutionServiceImplapplication/core/partner/webhook/impl/WebhookExecutionServiceImpl.javaLogic retry, tính backoff
TenantWebhookServiceapplication/core/partner/webhook/TenantWebhookService.javaTìm cấu hình webhook
TenantWebhookdomain/model/credentials/TenantWebhook.javaEntity cấu hình webhook
TenantAuthConfigdomain/model/credentials/TenantAuthConfig.javaEntity cấu hình auth
WebhookExecutiondomain/model/partner/WebhookExecution.javaEntity theo dõi execution
WebhookRetryWorkerinterfaces/worker/WebhookRetryWorker.javaWorker retry webhook thất bại
AuthLocationDtoapplication/core/partner/webhook/dto/AuthLocationDto.javaDTO cấu hình vị trí auth
TenantWebhookAdminControllerinterfaces/admin/generated/TenantWebhookAdminController.javaAdmin API quản lý cấu hình webhook

Tất cả đường dẫn tính từ simplize-core/src/main/java/com/simplize/core/


Xem thêm​