API Events
Licensing không có bề mặt messaging bất đồng bộ.
Application.configureComponents()chỉ đăng ký một Redis cache (useCacheRedis). Không có Kafka producer/consumer, không queue BullMQ, và không WebSocket emitter. Phụ thuộc@platformatic/kafkavàbullmqtrongpackage.jsonkhông được dùng.
1. Inbound — Kafka
| Topic | Producer | Handler | Idempotency Key | Failure Mode |
|---|---|---|---|---|
| Không | — | — | — | — |
2. Outbound — Kafka
| Topic | Trigger | Consumers | Payload Schema |
|---|---|---|---|
| Không | — | — | — |
3. Inbound — BullMQ
| Queue | Job Type | Producer | Handler | Concurrency |
|---|---|---|---|---|
| Không | — | — | — | — |
4. Outbound — BullMQ
| Queue | Job Type | Trigger | Consumer Service |
|---|---|---|---|
| Không | — | — | — |
5. WebSocket Emissions
| Topic | Room | Trigger | Action Enum |
|---|---|---|---|
| Không | — | — | — |
6. Payload Schemas
Payload xuyên service duy nhất là chứng chỉ license ghi vào Redis. Nó không phải sự kiện message-bus — nó là một key mà consumer kéo theo nhu cầu qua
LicenseMiddlewarecủa@nx/core.
Kênh chứng chỉ Redis
| Khía cạnh | Giá trị |
|---|---|
| Producer | LicensingBaseService.publishCertificate() — redis.client.set(key, cert, 'EX', certTtl) |
| Consumer | @nx/core LicenseProvider (tức LicenseMiddleware) — redis.client.get(key) |
| Key | lic:certs:<entityType>:<entityId> (vd lic:certs:Merchant:123) |
| Value | Envelope chuỗi Base64 (payload AES-256-GCM + chữ ký Ed25519) |
| TTL | APP_ENV_LICENSING_CERT_TTL_SECONDS (mặc định 86400) |
ts
// Payload chứng chỉ đã giải mã — ILicenseCertificatePayload (@nx/core)
export interface ILicenseCertificatePayload<FeaturesType = Record<string, unknown>> {
license: { id: string; key: string };
entity: { type: string; id: string };
status: string; // LicenseStatuses
tier: string; // policy.type (PolicyTypes)
features: FeaturesType; // map PolicyFeature đã giải (đã merge override)
activation: { limit: number } | null;
expiresAt: string | null;
issuedAt: string;
certExpiresAt: string; // độc lập với license.expiresAt — điều khiển Redis EX
}ts
// Envelope trên đường truyền — ICertificateEnvelope (@nx/core)
export interface ICertificateEnvelope {
enc: string; // ciphertext AES-256-GCM của JSON payload
sig: string; // chữ ký Ed25519 (base64url) trên "MESSAGE_PREFIX:enc"
alg: string; // "aes-256-gcm+ed25519"
}7. Idempotency & Thứ tự
| Bề mặt | Delivery | Thứ tự | Phục hồi |
|---|---|---|---|
| Chứng chỉ Redis | last-write-wins (một key mỗi entity) | n/a (chỉ trạng thái mới nhất) | Re-publish mỗi mutation vòng đời; hết hạn sau TTL → consumer thấy null (fail-open) cho tới khi re-issue |
Khi cert thiếu hoặc xác minh thất bại,
LicenseMiddlewarelà fail-open: nó đặt license context thànhnull(coi là "unknown", không phải "unlicensed").
8. Trang liên quan
- Integration — đường tin cậy với
@nx/core - Certificate System — chi tiết ký/xác minh
- Architecture — Kịch bản runtime