Skip to content

Kafka

IGNIS wraps @platformatic/kafka in four scoped helpers: producer, consumer, admin, and schema registry. Each adds health tracking, graceful shutdown, and IGNIS-style scoped logging over the raw client.

In one example

The smallest real use: create a producer, send a message through the underlying client, and close it.

typescript
import { KafkaProducerHelper } from '@venizia/ignis-helpers/kafka';
import { stringSerializers } from '@platformatic/kafka';

const producer = KafkaProducerHelper.newInstance({
  bootstrapBrokers: ['localhost:9092'],
  clientId: 'order-producer',
  serializers: stringSerializers,
});

await producer.getProducer().send({
  messages: [{ topic: 'orders', key: 'order-1', value: JSON.stringify({ status: 'created' }) }],
});

await producer.close();

getProducer() returns the full @platformatic/kafka Producer. Every helper follows the same three-step pattern:

StepCall
ConstructnewInstance()
Reach the native clientgetProducer() / getConsumer() / getAdmin()
Closethrough the helper, not the native client

Which helper do I need

ClassWrapsUse it to
KafkaProducerHelperProducerPublish messages, run transactions
KafkaConsumerHelperConsumerConsume via consumer groups, monitor lag
KafkaAdminHelperAdminManage topics, partitions, groups, ACLs, configs
KafkaSchemaRegistryHelperConfluentSchemaRegistrySchema-validated serialization (Avro/Protobuf/JSON Schema)

A few facts hold across all four:

  • Producer, consumer, and admin share one health and close API. isHealthy(), isReady(), getHealthStatus(), and close({ isForce }) mean the same thing on every class. Each page documents the exact return values.
  • Schema registry opens no broker connection. It extends BaseHelper directly, not the shared connected-helper base. It has no health tracking - it's a configuration wrapper you hand to a producer or consumer via registry.
  • Everything lives under /kafka, never the root barrel. Install the optional peer yourself: bun add @platformatic/kafka (^2.6.1). An app that never touches Kafka tree-shakes it away entirely.
  • Compiling to a single binary needs one extra build step. Skip it, and the compiled app crashes at startup with ENOENT: native.wasm or Cannot find package 'ajv-draft-04' - see Compiling to a Single Binary.
  • Defaults and enum-like values ship as exported constants, not magic numbers - KafkaDefaults, KafkaAcks, KafkaGroupProtocol, KafkaHealthStatuses. Each page's options table names the constant it uses.

Find what you need

You want toGo to
Publish messages, set up SASL/TLS, run transactionsProducer
Consume messages, monitor lag, handle reconnectsConsumer
Create or delete topics, inspect consumer groups, manage ACLsAdmin
Validate message shape with Avro, Protobuf, or JSON SchemaSchema Registry
See end-to-end examples or fix a connection errorExamples & Troubleshooting
Ship an app that imports a Kafka helper as a single binaryCompiling to a Single Binary

Start with Producer or Consumer if you're wiring up your first topic. Start with Compiling to a Single Binary if an existing app started crashing at startup after a bun build --compile.

See also

Files: