addCorrelationId
Αυτό το περιεχόμενο δεν είναι ακόμη διαθέσιμο στη γλώσσα σου.
addCorrelationId<
T>(data):WithCorrelationId<T>
Defined in: correlation.store.ts:163
Stamp the current correlation ID onto a data object.
This is the producer-side counterpart to WithCorrelation:
addCorrelationId(data)→ stamps the ID when enqueuing a job / publishing a message@WithCorrelation()→ extracts the ID when processing the job / handling the message
Both default to the 'correlationId' key, so they work together out of the box.
Type Parameters
Section titled “Type Parameters”T extends Record<string, unknown>
Parameters
Section titled “Parameters”T
The payload to enrich. Must be a plain object, not an array. A shallow copy is returned; the original is not mutated.
Returns
Section titled “Returns”A new object with correlationId added.
Throws
Section titled “Throws”If data is not a plain object.
Example
Section titled “Example”// Bull / BullMQawait queue.add('send-email', addCorrelationId({ userId, email }));
// RabbitMQ (ClientProxy)this.client.emit('user.created', addCorrelationId(payload));
// Kafkaawait this.producer.send({ topic: 'orders', messages: [{ value: JSON.stringify(addCorrelationId(order)) }],});
// PostgreSQL NOTIFYawait sql`SELECT pg_notify('events', ${JSON.stringify(addCorrelationId(data))})`;
// ⚠️ Arrays must be wrapped — passing one directly throws:// addCorrelationId([item1, item2]); // ❌ TypeErroraddCorrelationId({ items: [item1, item2] }); // ✅