Kind: Interface
Source: packages/microservices/external/kafka.interface.ts
Part of: Microservices
KafkaJSRequestTimeoutErrorMetadata describes diagnostic timing and routing details for a KafkaJS request that exceeded its timeout. It captures the target broker, client identity, correlation ID, and timestamps needed to calculate how long the request remained pending.
Properties
| Property | Type |
|---|---|
broker | string |
clientId | string |
correlationId | number |
createdAt | number |
sentAt | number |
pendingDuration | number |
Diagram
mermaidgraph LR Client[Kafka Client] -->|request| Broker[Kafka Broker] Client --> Metadata[KafkaJSRequestTimeoutErrorMetadata] Metadata --> B[broker: string] Metadata --> C[clientId: string] Metadata --> CID[correlationId: number] Metadata --> CA[createdAt: number] Metadata --> SA[sentAt: number] Metadata --> PD[pendingDuration: number] Broker -->|timeout| Error[Request Timeout Error] Metadata --> Error
Usage
tsimport type { KafkaJSRequestTimeoutErrorMetadata } from './kafka.interface';
function logRequestTimeout(
metadata: KafkaJSRequestTimeoutErrorMetadata,
): void {
console.error('Kafka request timed out', {
broker: metadata.broker,
clientId: metadata.clientId,
correlationId: metadata.correlationId,
pendingDurationMs: metadata.pendingDuration,
createdAt: new Date(metadata.createdAt).toISOString(),
sentAt: new Date(metadata.sentAt).toISOString(),
});
}
const timeoutMetadata: KafkaJSRequestTimeoutErrorMetadata = {
broker: 'localhost:9092',
clientId: 'orders-service',
correlationId: 42,
createdAt: Date.now() - 10_000,
sentAt: Date.now() - 9_500,
pendingDuration: 9_500,
};
logRequestTimeout(timeoutMetadata);
AI Coding Instructions
- Treat
createdAt,sentAt, andpendingDurationas millisecond-based numeric timestamps/durations. - Preserve the original
broker,clientId, andcorrelationIdvalues when wrapping or rethrowing Kafka timeout errors. - Use this metadata for structured logging, tracing attributes, and timeout diagnostics rather than user-facing error messages.
- Do not assume
pendingDurationis equivalent to total application processing time; it represents the Kafka request's pending duration.
Was this page helpful?