fix(mining-admin): use outbox_id for event idempotency key
The outbox_events table uses outbox_id as the primary key column name (mapped from id in Prisma). When Debezium captures changes, the message contains outbox_id field, not id. This caused all events to have undefined eventId, resulting in duplicate detection treating all events as duplicates after the first one. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
e981e622d4
commit
5e16adc1ec
|
|
@ -324,12 +324,18 @@ export class CdcConsumerService implements OnModuleInit, OnModuleDestroy {
|
|||
|
||||
// Debezium outbox 格式转换
|
||||
// 原始格式:{ event_type, aggregate_type, aggregate_id, payload (JSON string), ... }
|
||||
// 注意:不同服务的 outbox 表主键列名可能不同:
|
||||
// - contribution-service: outbox_id (mapped from id in Prisma)
|
||||
// - 其他服务可能使用: id
|
||||
const payload = typeof data.payload === 'string'
|
||||
? JSON.parse(data.payload)
|
||||
: data.payload;
|
||||
|
||||
// 优先使用 outbox_id(contribution-service),回退到 id
|
||||
const eventId = data.outbox_id ?? data.id;
|
||||
|
||||
return {
|
||||
id: String(data.id),
|
||||
id: String(eventId),
|
||||
eventType: data.event_type,
|
||||
aggregateType: data.aggregate_type,
|
||||
aggregateId: data.aggregate_id,
|
||||
|
|
|
|||
Loading…
Reference in New Issue