Skip to content

API Events

1. Inbound — Kafka

TopicConstantProducerHandlerFailure Mode
signal.activity-notificationKafkaTopics.SIGNAL_ACTIVITY_NOTIFICATIONSale / Payment (khi thanh toán thành công)ActivityNotificationWorkerService.handleActivityNotificationlog khi lỗi, không retry/DLQ; offset commit theo từng message sau khi xử lý

Config consumer (NotificationKafkaComponent):

Cài đặtGiá trị
autocommitfalse (message.commit() thủ công sau mỗi handler)
fallbackModelatest
clientIdAPP_ENV_KAFKA_CLIENT_ID ?? ${ServiceCodes.SIGNAL}_NOTIF_CONSUMER
groupIdAPP_ENV_KAFKA_GROUP_ID ?? ${ServiceCodes.SIGNAL}_NOTIF_CONSUMER_GROUP
deserializerskey: string, value: json
shutdownSIGTERM / SIGINTconsumer.close() graceful

2. Outbound — Kafka

Không. Signal chỉ consume; nó không bao giờ sản xuất sự kiện Kafka.

3. Inbound — BullMQ

Không.

4. Outbound — BullMQ

Không.

5. WebSocket Emissions

TopicRoomTriggerEmit bởi
observation/signal/notification/createdsignal/notification/{recipientId}Sau khi lưu hàng notificationNotificationSocketEventService.notifyActivityNotificationCreated
(caller định nghĩa)broadcast (all)POST /socket/websocket/clients/broadcastSignalEventService.broadcast
(caller định nghĩa){roomName}POST /socket/websocket/clients/rooms/{roomName}/sendSignalEventService.sendToRoom
(caller định nghĩa)single clientPOST /socket/websocket/clients/{clientId}/send hoặc cross-service WebSocketEmitter.toClientSignalEventService.sendToClient

Builder topic/room: NotificationWebSocketTopics (topics.ts) và NotificationWebSocketRooms (rooms.ts), cả hai dựng qua WebSocketTopics.build / WebSocketRooms.build từ @nx/core.

6. Payload Schemas

Message Kafka inboundTActivityNotificationMessage (packages/core/src/common/kafka/types.ts):

ts
type TActivityNotificationMessage = {
  eventType: TActivityNotificationTypes;          // 'PAYMENT_SUCCESS'
  recipientScope: 'org' | 'merchant' | 'users';
  actorId: string;
  actor: { id: string; name: string; type: string };
  organizerId: string;
  merchantId?: string;
  recipientIds?: string[];                         // dùng khi scope = 'users'
  data: Record<string, unknown>;                   // vd { payment: { subject } }
  occurredAt: string;
};

Payload WebSocket outbound (notification.created):

ts
interface NotificationCreatedPayload {
  id: string;
  type: string;                  // ActivityNotification.type
  organizerId: string | null;
  content: string;
  actionUrl: string | null;
  data: Record<string, unknown>;
  isRead: boolean;
  createdAt: string;
}

7. Idempotency & Thứ tự

TopicDeliveryThứ tựPhục hồi
signal.activity-notificationat-least-oncetheo partitionkhông dedup — một message re-deliver tạo hàng ActivityNotification trùng; cần dọn thủ công

Xem ADR-0002 cho thiết kế persist-then-push và lỗ hổng idempotency đã biết.

8. Trang liên quan

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.