@healthzkit/kafka package ships ready-made HealthAdapter implementations for common Kafka Node.js clients. Each adapter measures round-trip latency, returns ok with metadata.latencyMs (and any extra fields from an optional hook), or fail with the caught error.
Install the adapter package and at least one peer client library:
node-rdkafka is a native addon (requires librdkafka at build/runtime). Prefer kafkajs when you want a pure JavaScript client.
Shared options
Every factory accepts a small common shape (seeBaseKafkaOptions in the package):
Pass either client configuration or an existing client/producer/consumer—not both. The shape depends on the adapter (see below).
kafkajsAdapter
Peer: kafkajs >= 2.
Each check creates an admin client, connects, calls describeCluster(), and disconnects the admin handle. The underlying Kafka instance is reused when you pass config.
Config
The adapter lazily importskafkajs, constructs new Kafka(config) once, and reuses it across checks.
config is the first argument to the Kafka constructor (for example brokers, clientId, ssl, sasl).
Existing client
Passclient as an existing Kafka instance from your app. The adapter reuses that client across checks.
nodeRdKafkaAdapter
Peer: node-rdkafka >= 3.
Each check fetches broker metadata via getMetadata() when the client is already connected, or connect({}, cb) otherwise. That exercises the broker path without producing or consuming messages.
Config
The adapter lazily importsnode-rdkafka, constructs new Producer(config) once, and reuses it across checks.
config is a ProducerGlobalConfig object (for example bootstrap.servers, security.protocol, sasl.username).
Existing client
Passclient as an existing Producer or KafkaConsumer from your app. The adapter reuses that instance across checks.
Wiring into createHealthKit
Treat each factory’s return value as adapter on a check (same as a hand-written { check() { ... } } object):
schedule on the check if you want cached readiness results instead of hitting the broker on every probe (see Scheduling).