Kafka Integration Skill
You are an expert in integrating Apache Kafka with Platformatic Watt for event-driven microservices.
Prerequisites Check
Before any Kafka setup, verify:
Node.js Version: Watt requires Node.js v22.19.0+
node --version
If below v22.19.0, inform user they must upgrade Node.js first.
Existing Watt Config: Check if watt.json already exists
ls watt.json 2>/dev/null
If no watt.json, suggest running /watt init first to set up Watt.
Command Router
Based on user input ($ARGUMENTS), route to the appropriate workflow:
| Input Pattern |
Action |
hooks, webhooks, (empty) |
Run Kafka-Hooks Setup |
producer, consumer, client |
Run Kafka Client Setup |
monitoring, lag, health |
Run Consumer Lag Monitoring Setup |
tracing, opentelemetry, otel |
Run Kafka Tracing Setup |
migrate kafkajs, kafkajs, replace kafkajs |
Run KafkaJS Migration Workflow |
migrate node-rdkafka, node-rdkafka, node rdkafka, rdkafka, librdkafka, Kafka.Producer, Kafka.KafkaConsumer, ProducerStream, ConsumerStream |
Run node-rdkafka Migration Workflow |
migrate, migration |
Run Migration Detection Workflow |
Kafka-Hooks Setup
When user requests Kafka webhook/hook integration:
- Read references/kafka.md
- Choose integration approach:
- @platformatic/kafka-hooks: Kafka-to-HTTP webhooks (recommended for Watt)
- @platformatic/kafka: Direct producer/consumer in your services
- Create kafka-hooks service with
npx wattpm@latest create
- Configure topics, webhooks, and request/response patterns
Kafka-Hooks Patterns
- Webhook: Kafka messages → HTTP endpoints (with DLQ)
- Request/Response: HTTP → Kafka → HTTP (correlation IDs)
- HTTP Publishing: POST to
/topics/{topicName}
Kafka Client Setup
When user requests direct Kafka producer/consumer integration:
- Read references/kafka.md
- Install
@platformatic/kafka:npm install @platformatic/kafka
- Set up producer and/or consumer in the target service
- Configure serializers/deserializers based on message format
Consumer Lag Monitoring Setup
When user requests Kafka consumer lag monitoring:
- Read references/kafka.md
- Install
@platformatic/watt-plugin-kafka-health:npm install @platformatic/watt-plugin-kafka-health
- Add plugin to service
watt.json
- Configure lag threshold and check interval
Kafka Tracing Setup
When user requests OpenTelemetry tracing for Kafka:
- Read references/kafka.md
- Install
@platformatic/kafka-opentelemetry:npm install @platformatic/kafka-opentelemetry
- Enable instrumentation in the service
KafkaJS Migration Workflow
When user wants to migrate from KafkaJS to @platformatic/kafka:
- Read references/kafkajs-migration.md
- Scan the project for KafkaJS usage patterns:
require('kafkajs') or from 'kafkajs' imports
new Kafka({...}) factory instantiation
.producer(), .consumer(), .admin() calls
connect() / disconnect() lifecycle calls
subscribe() + run({ eachMessage }) consumer pattern
sendBatch() calls
CompressionTypes usage
transaction() calls
- Error handling with
KafkaJS* error classes
- Apply the migration checklist from the reference, transforming each pattern
- Verify the migration covers all areas:
- Client creation (factory → direct instantiation)
- Connection lifecycle (
connect/disconnect → lazy/close)
- Producer API (topic per-send → topic per-message, serializers)
- Consumer API (callback → stream, offset modes)
- Admin API (new method signatures)
- Error handling (
retriable → canRetry, new error classes)
- Events (custom events →
diagnostics_channel)
node-rdkafka Migration Workflow
When user wants to migrate from node-rdkafka to @platformatic/kafka:
- Read references/node-rdkafka-migration.md
- Scan the project for node-rdkafka usage patterns:
require('node-rdkafka') or from 'node-rdkafka' imports
new Kafka.Producer(...)
new Kafka.KafkaConsumer(...)
Kafka.Producer.createWriteStream(...)
Kafka.KafkaConsumer.createReadStream(...)
.produce(...), .poll(), .consume(...), .subscribe(...)
.connect(...), .disconnect(...), .on('ready'), .on('data'), .on('event.error')
.getMetadata(...)
- librdkafka options such as
metadata.broker.list, group.id, enable.auto.commit, security.protocol, sasl.mechanisms
- Replace
node-rdkafka with @platformatic/kafka in dependencies using the detected package manager
- Transform producers first, then consumers, then stream wrappers, then metadata/admin usage
- Update shutdown paths from callback/event disconnects to
await client.close()
- Verify the migration checklist from the reference
Migration Detection Workflow
When user asks for a Kafka migration but does not specify the source client:
- Inspect
package.json and lockfiles for kafkajs or node-rdkafka
- Search source files for imports from
kafkajs or node-rdkafka
- If KafkaJS is found, run KafkaJS Migration Workflow
- If node-rdkafka is found, run node-rdkafka Migration Workflow
- If both are found, migrate one client at a time and start with the one with fewer call sites
- If neither is found, ask the user which Kafka client they are migrating from
Important Notes
- Internal service URLs:
http://{service-id}.plt.local
- Environment variables in watt.json use
{VAR_NAME} (curly braces, no dollar sign)
- Kafka-hooks is the recommended approach for Watt multi-service architectures
- Always configure Dead Letter Queues (DLQ) for production webhook topics
1---2name: kafka3description: Set up Kafka-based event-driven microservices with Platformatic Watt. Use when users ask about: - "kafka", "event-driven", "messaging" - "kafka hooks", "kafka webhooks" - "kafka producer", "kafka consumer" - "dead letter queue", "DLQ" - "request response pattern" with Kafka - "migrate from kafkajs", "kafkajs migration", "replace kafkajs" - "node-rdkafka", "node rdkafka", "rdkafka", "librdkafka" - "migrate from node-rdkafka", "replace node-rdkafka" - "Kafka.Producer", "Kafka.KafkaConsumer", "ProducerStream", "ConsumerStream" Covers @platformatic/kafka, @platformatic/kafka-hooks, consumer lag monitoring, OpenTelemetry instrumentation, and migrations from KafkaJS or node-rdkafka.4---56# Kafka Integration Skill78You are an expert in integrating Apache Kafka with Platformatic Watt for event-driven microservices.910## Prerequisites Check1112Before any Kafka setup, verify:13141. **Node.js Version**: Watt requires Node.js v22.19.0+15 ```bash16 node --version17 ```18 If below v22.19.0, inform user they must upgrade Node.js first.19202. **Existing Watt Config**: Check if `watt.json` already exists21 ```bash22 ls watt.json 2>/dev/null23 ```24 If no `watt.json`, suggest running `/watt init` first to set up Watt.2526## Command Router2728Based on user input ($ARGUMENTS), route to the appropriate workflow:2930| Input Pattern | Action |31|--------------|--------|32| `hooks`, `webhooks`, (empty) | Run **Kafka-Hooks Setup** |33| `producer`, `consumer`, `client` | Run **Kafka Client Setup** |34| `monitoring`, `lag`, `health` | Run **Consumer Lag Monitoring Setup** |35| `tracing`, `opentelemetry`, `otel` | Run **Kafka Tracing Setup** |36| `migrate kafkajs`, `kafkajs`, `replace kafkajs` | Run **KafkaJS Migration Workflow** |37| `migrate node-rdkafka`, `node-rdkafka`, `node rdkafka`, `rdkafka`, `librdkafka`, `Kafka.Producer`, `Kafka.KafkaConsumer`, `ProducerStream`, `ConsumerStream` | Run **node-rdkafka Migration Workflow** |38| `migrate`, `migration` | Run **Migration Detection Workflow** |3940---4142## Kafka-Hooks Setup4344When user requests Kafka webhook/hook integration:45461. Read [references/kafka.md](references/kafka.md)472. Choose integration approach:48 - **@platformatic/kafka-hooks**: Kafka-to-HTTP webhooks (recommended for Watt)49 - **@platformatic/kafka**: Direct producer/consumer in your services503. Create kafka-hooks service with `npx wattpm@latest create`514. Configure topics, webhooks, and request/response patterns5253### Kafka-Hooks Patterns5455- **Webhook**: Kafka messages → HTTP endpoints (with DLQ)56- **Request/Response**: HTTP → Kafka → HTTP (correlation IDs)57- **HTTP Publishing**: POST to `/topics/{topicName}`5859---6061## Kafka Client Setup6263When user requests direct Kafka producer/consumer integration:64651. Read [references/kafka.md](references/kafka.md)662. Install `@platformatic/kafka`:67 ```bash68 npm install @platformatic/kafka69 ```703. Set up producer and/or consumer in the target service714. Configure serializers/deserializers based on message format7273---7475## Consumer Lag Monitoring Setup7677When user requests Kafka consumer lag monitoring:78791. Read [references/kafka.md](references/kafka.md)802. Install `@platformatic/watt-plugin-kafka-health`:81 ```bash82 npm install @platformatic/watt-plugin-kafka-health83 ```843. Add plugin to service `watt.json`854. Configure lag threshold and check interval8687---8889## Kafka Tracing Setup9091When user requests OpenTelemetry tracing for Kafka:92931. Read [references/kafka.md](references/kafka.md)942. Install `@platformatic/kafka-opentelemetry`:95 ```bash96 npm install @platformatic/kafka-opentelemetry97 ```983. Enable instrumentation in the service99100---101102## KafkaJS Migration Workflow103104When user wants to migrate from KafkaJS to @platformatic/kafka:1051061. Read [references/kafkajs-migration.md](references/kafkajs-migration.md)1072. Scan the project for KafkaJS usage patterns:108 - `require('kafkajs')` or `from 'kafkajs'` imports109 - `new Kafka({...})` factory instantiation110 - `.producer()`, `.consumer()`, `.admin()` calls111 - `connect()` / `disconnect()` lifecycle calls112 - `subscribe()` + `run({ eachMessage })` consumer pattern113 - `sendBatch()` calls114 - `CompressionTypes` usage115 - `transaction()` calls116 - Error handling with `KafkaJS*` error classes1173. Apply the migration checklist from the reference, transforming each pattern1184. Verify the migration covers all areas:119 - Client creation (factory → direct instantiation)120 - Connection lifecycle (`connect`/`disconnect` → lazy/`close`)121 - Producer API (topic per-send → topic per-message, serializers)122 - Consumer API (callback → stream, offset modes)123 - Admin API (new method signatures)124 - Error handling (`retriable` → `canRetry`, new error classes)125 - Events (custom events → `diagnostics_channel`)126127---128129## node-rdkafka Migration Workflow130131When user wants to migrate from node-rdkafka to @platformatic/kafka:1321331. Read [references/node-rdkafka-migration.md](references/node-rdkafka-migration.md)1342. Scan the project for node-rdkafka usage patterns:135 - `require('node-rdkafka')` or `from 'node-rdkafka'` imports136 - `new Kafka.Producer(...)`137 - `new Kafka.KafkaConsumer(...)`138 - `Kafka.Producer.createWriteStream(...)`139 - `Kafka.KafkaConsumer.createReadStream(...)`140 - `.produce(...)`, `.poll()`, `.consume(...)`, `.subscribe(...)`141 - `.connect(...)`, `.disconnect(...)`, `.on('ready')`, `.on('data')`, `.on('event.error')`142 - `.getMetadata(...)`143 - librdkafka options such as `metadata.broker.list`, `group.id`, `enable.auto.commit`, `security.protocol`, `sasl.mechanisms`1443. Replace `node-rdkafka` with `@platformatic/kafka` in dependencies using the detected package manager1454. Transform producers first, then consumers, then stream wrappers, then metadata/admin usage1465. Update shutdown paths from callback/event disconnects to `await client.close()`1476. Verify the migration checklist from the reference148149---150151## Migration Detection Workflow152153When user asks for a Kafka migration but does not specify the source client:1541551. Inspect `package.json` and lockfiles for `kafkajs` or `node-rdkafka`1562. Search source files for imports from `kafkajs` or `node-rdkafka`1573. If KafkaJS is found, run **KafkaJS Migration Workflow**1584. If node-rdkafka is found, run **node-rdkafka Migration Workflow**1595. If both are found, migrate one client at a time and start with the one with fewer call sites1606. If neither is found, ask the user which Kafka client they are migrating from161162---163164## Important Notes165166- Internal service URLs: `http://{service-id}.plt.local`167- Environment variables in watt.json use `{VAR_NAME}` (curly braces, no dollar sign)168- Kafka-hooks is the recommended approach for Watt multi-service architectures169- Always configure Dead Letter Queues (DLQ) for production webhook topics