Files
wwjcloud-nest-v1/wwjcloud/test/test.service.ts

40 lines
1.1 KiB
TypeScript
Raw Normal View History

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<string, any>,
): Promise<void> {
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<string, any>,
): Promise<string> {
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)}`;
}
}