Skip to content

KafkaJSConnectionErrorMetadata

reference
1 min readUpdated

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

PropertyType
brokerstring
codestring

Diagram

mermaid
graph 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

ts
import 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 broker and code when creating this metadata object.
  • Use the broker value to identify the exact Kafka endpoint, typically in host:port format.
  • 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 broker field.

Was this page helpful?

Download as PDF
KafkaJSConnectionErrorMetadata — NestJS head-to-head