import { Injectable } from '@nestjs/common'; import { UnifiedQueueService } from '@wwjCore/queue/unifiedQueueService'; @Injectable() export class TestService { constructor(private readonly unifiedQueueService: UnifiedQueueService) {} async publishKafkaEvent( topic: string, data: Record, ): Promise { await this.unifiedQueueService.publishEvent({ eventType: topic, aggregateId: 'test-aggregate', aggregateType: 'Test', version: '1.0', occurredAt: new Date().toISOString(), tenantId: '0', idempotencyKey: `key_${Date.now()}`, traceId: `trace_${Date.now()}`, data, }); } async enqueueRedisJob( type: string, payload: Record, ): Promise { await this.unifiedQueueService.addTask('test-queue', type, payload, { attempts: 3, backoff: { type: 'fixed', delay: 1000 }, removeOnComplete: true, removeOnFail: false, }); // 生成一个模拟的 job ID(测试用) return `job_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`; } }