Kind: Interface
Source: packages/microservices/external/kafka.interface.ts
Part of: Microservices
KafkaJSConnectionErrorMetadata describes connection-specific metadata reported when a KafkaJS broker connection fails. It identifies the affected broker endpoint and the associated Kafka error code, allowing microservice error handling and logging to provide actionable diagnostics.
Properties
| Property | Type |
|---|---|
broker | string |
code | string |
Diagram
mermaidgraph LR A[KafkaJS broker connection attempt] --> B{Connection error} B --> C[KafkaJSConnectionErrorMetadata] C --> D[broker: string] C --> E[code: string] C --> F[Logging / retry / error handling]
Usage
tsimport type { KafkaJSConnectionErrorMetadata } from './kafka.interface';
function logKafkaConnectionError(
metadata: KafkaJSConnectionErrorMetadata,
): void {
console.error(
`Kafka connection failed for broker ${metadata.broker} (${metadata.code})`,
);
}
const connectionError: KafkaJSConnectionErrorMetadata = {
broker: 'localhost:9092',
code: 'ECONNREFUSED',
};
logKafkaConnectionError(connectionError);
AI Coding Instructions
- Always provide both
brokerandcodewhen creating this metadata object. - Use the broker value to identify the exact Kafka endpoint, typically in
host:portformat. - Preserve the original KafkaJS or Node.js connection error code where possible; do not replace it with a generic message.
- Integrate this metadata into structured logs, retry decisions, and exception diagnostics.
- Avoid storing credentials or sensitive connection details in the
brokerfield.
Was this page helpful?