diff --git a/backend/services/contribution-service/src/infrastructure/kafka/kafka-producer.service.ts b/backend/services/contribution-service/src/infrastructure/kafka/kafka-producer.service.ts index 6227552c..28f83f9e 100644 --- a/backend/services/contribution-service/src/infrastructure/kafka/kafka-producer.service.ts +++ b/backend/services/contribution-service/src/infrastructure/kafka/kafka-producer.service.ts @@ -25,7 +25,7 @@ export class KafkaProducerService implements OnModuleInit { await lastValueFrom( this.kafkaClient.emit(topic, { key: message.key, - value: JSON.stringify(message.value), + value: JSON.stringify(message.value, this.bigIntReplacer), headers: message.headers, }), ); @@ -36,6 +36,16 @@ export class KafkaProducerService implements OnModuleInit { } } + /** + * JSON.stringify replacer 函数,将 BigInt 转换为字符串 + */ + private bigIntReplacer(_key: string, value: any): any { + if (typeof value === 'bigint') { + return value.toString(); + } + return value; + } + async emitBatch(topic: string, messages: KafkaMessage[]): Promise { try { for (const message of messages) {