Μετάβαση στο περιεχόμενο

correlationHeaders

Αυτό το περιεχόμενο δεν είναι ακόμη διαθέσιμο στη γλώσσα σου.

correlationHeaders(key?): Record<string, string>

Defined in: correlation.store.ts:214

Return a headers object stamped with the current correlation ID.

Use this for header-based transports (Kafka, NATS, gRPC metadata, HTTP) where the correlation ID belongs in message headers / metadata — not in the data payload.

For transports without native headers (Bull/BullMQ, PostgreSQL NOTIFY), use addCorrelationId instead.

string = DEFAULT_CORRELATION_HEADER

Header name. Defaults to 'x-correlation-id'.

Record<string, string>

{ [key]: correlationId } — spread into your transport’s headers.

// Kafka
await producer.send({
topic: 'orders',
messages: [{ value: JSON.stringify(order), headers: correlationHeaders() }],
});
// RabbitMQ (amqplib) — AMQP has a first-class correlationId property:
channel.publish(exchange, key, buffer, { correlationId: getCorrelationId() });
// …or in headers:
channel.publish(exchange, key, buffer, { headers: correlationHeaders() });
// NATS
const headers = nats.headers();
Object.entries(correlationHeaders()).forEach(([k, v]) => headers.set(k, v));
nc.publish(subject, payload, { headers });
// HTTP (outgoing)
await fetch(url, { headers: { ...correlationHeaders(), 'content-type': 'application/json' } });