Skip to content

API Events

@nx/search là một CDC consumer. Nó subscribe 18 Debezium topic và chỉ produce tới một dead-letter queue. Không có business event outbound, không WebSocket, không BullMQ. Đặt tên topic theo Debezium {prefix}.{schema}.{table} với prefix nx.seller.

1. Inbound — Kafka (CDC)

Tất cả topic định nghĩa trong SearchCollections.CDC (src/common/kafka-topics.ts); consumer subscribe ALL_CDC_TOPICS. Handler là CDCService.handleBatch() cho mọi topic.

Direct document sources (map trong TableToCollectionMap)

TopicSchema.Table→ Collection
nx.seller.public.Organizerpublic.Organizerorganizers
nx.seller.public.Merchantpublic.Merchantmerchants
nx.seller.public.Categorypublic.Categorycategories
nx.seller.public.Devicepublic.Devicedevices
nx.seller.public.SaleChannelpublic.SaleChannelsale-channels
nx.seller.public.Productpublic.Productproducts
nx.seller.public.ProductInfopublic.ProductInfoproducts (i18n partial)
nx.seller.public.ProductVariantpublic.ProductVariantproduct-variants
nx.seller.inventory.InventoryStockinventory.InventoryStockinventories

Cascade-only sources (không phải direct doc source — fan out qua CDCCascadeService)

TopicSchema.TableTính lại
nx.seller.public.ProductCategorypublic.ProductCategoryproducts + product-variants categoryIds
nx.seller.public.MetaLinkpublic.MetaLinkproduct → variant productMetaLinks; variant metaLinks
nx.seller.pricing.FareSetpricing.FareSetvariant fareSet + defaultPrice
nx.seller.pricing.Farepricing.Farevariant fareSet + defaultPrice
nx.seller.public.ProductBundlerpublic.ProductBundlervariant comboItems
nx.seller.inventory.InventoryIteminventory.InventoryItemnhóm item inventories
nx.seller.inventory.InventoryLocationinventory.InventoryLocationnhóm location inventories
nx.seller.inventory.InventoryIdentifierinventory.InventoryIdentifierinventories identifiers[]
nx.seller.inventory.Materialinventory.Materialitem inventories (kiểu Material)

Op code Debezium

OpÝ nghĩaAction
ccreateupsert doc
uupdateupsert doc
ddeletedelete doc
rsnapshot readupsert doc (initial load)

Bất kỳ op nào mà mapper trả về null (soft-deleted) trở thành một Typesense delete.

2. Outbound — Kafka

TopicTriggerConsumersPayload
nx.seller.cdc.dlq (mặc định, override qua APP_ENV_CDC_DLQ_TOPIC)Một message CDC fail xử lý sau retryOps / tooling replay thủ côngMessage CDC gốc + metadata lỗi

3. Inbound — BullMQ

N/A — không có BullMQ consumer. (Thiết kế embedding-queue trong selection report là một tùy chọn tương lai, chưa implement.)

4. Outbound — BullMQ

N/A — không có BullMQ producer.

5. WebSocket Emissions

N/A — thư viện không emit WebSocket event nào. Cập nhật UI real-time là mối quan tâm của host service.

6. Payload Schemas

Payload CDC là Debezium envelope, giải mã với avsc. Search không sở hữu các schema này — chúng phản chiếu bảng nguồn. Shape (rút gọn):

ts
// Debezium change event (Avro-decoded)
interface DebeziumEnvelope<TBefore, TAfter> {
  op: 'c' | 'u' | 'd' | 'r';
  before: TBefore | null;
  after: TAfter | null;
  source: {
    schema: string;     // public | pricing | inventory
    table: string;      // vd "Product"
    lsn: number;        // → guard replay sai thứ tự (SearchVersionFields.SOURCE_LSN)
    ts_ms: number;
  };
}

Tham số query search (hướng consumer, ISearchParams):

ts
interface ISearchParams {
  q?: string;                    // mặc định '*'
  limit?: number;                // mặc định 10, max 250
  offset?: number;
  where?: unknown;               // kiểu Ignis → filter_by
  order?: string | string[];     // "createdAt DESC" → sort_by
  include?: IIncludeSpec[];      // hydration quan hệ / native join
  useCache?: boolean;
  cacheTtl?: number;
  disableSemanticSearch?: boolean; // bỏ embedding khỏi query_by (keyword nghiêm ngặt)
}

7. Idempotency & Ordering

Topic classDeliveryOrderingRecovery
Tất cả topic CDCat-least-once (auto-commit off; commit sau batch)per-key qua Debezium; guard LSN loại bỏ event cũđọc lại offset chưa-commit sau restart / circuit-breaker close
DLQfire-and-forgetreplay thủ công
GuardFieldHiệu ứng
LSNsource_lsn (SearchVersionFields.SOURCE_LSN)Skip event nếu LSN của nó ≤ LSN doc đã lưu
Tombstonedeleted_at (SearchVersionFields.DELETED_AT)So sánh để giữ delete khỏi bị hoàn tác bởi upsert cũ

8. Trang liên quan

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