runWithCorrelationId
Αυτό το περιεχόμενο δεν είναι ακόμη διαθέσιμο στη γλώσσα σου.
runWithCorrelationId<
T>(correlationId,fn):T
Defined in: correlation.store.ts:113
Run a callback within a correlation context.
Use this in non-HTTP entry points (Bull processors, RabbitMQ handlers, WebSocket gateways, cron jobs, etc.) to propagate an external correlation ID into any CQRS commands or queries dispatched inside the callback.
If correlationId is missing, empty, or not printable ASCII without
surrounding spaces (the check every write to the store applies), the id is
resolved via getCorrelationId (the current one, or a new one from
correlationSource.create()), so fn always runs with a correlation id. A
pipeline dispatched inside fn takes it as its context.correlationId.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”correlationId
Section titled “correlationId”string | undefined
The correlation ID to propagate. If missing or malformed, falls back to getCorrelationId.
() => T
The callback to execute within the correlation context.
Returns
Section titled “Returns”T
Example
Section titled “Example”// Bull processor@Processor('my-queue')export class MyProcessor { @Process() async handle(job: Job) { return runWithCorrelationId(job.data.correlationId, () => this.commandBus.execute(new MyCommand(job.data)), ); }}
// RabbitMQ microservice handler@MessagePattern('user.created')async handle(@Payload() data: any, @Ctx() ctx: RmqContext) { const id = ctx.getMessage().properties.correlationId; return runWithCorrelationId(id, () => this.commandBus.execute(new MyCommand(data)), );}
// Cron job@Cron('0 * * * *')async hourlySync() { return runWithCorrelationId(randomUUID(), () => this.commandBus.execute(new SyncCommand()), );}