Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions docs/modules/kafkajs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
description: Modern alternatives to the kafkajs package
---

# Replacements for `kafkajs`

`kafkajs` is [no longer maintained](https://github.com/tulios/kafkajs/issues/1603). Both replacements below are actively maintained [Kafka](https://kafka.apache.org/) clients; choose based on your runtime and migration requirements.

## `@platformatic/kafka`

[`@platformatic/kafka`](https://github.com/platformatic/kafka) is a modern, pure TypeScript/JavaScript Kafka client with no native addon. It uses separate producer, consumer, and admin clients, and provides type-safe APIs, serializers, and stream-based consumers.

Example:

<!-- prettier-ignore -->
```js
const { Kafka } = require('kafkajs') // [!code --]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we really should be using ESM in the examples i think

const { Producer, stringSerializers } = require('@platformatic/kafka') // [!code ++]

const kafka = new Kafka({ // [!code --]
clientId: 'my-app', // [!code --]
brokers: ['localhost:9092'] // [!code --]
}) // [!code --]
const producer = kafka.producer() // [!code --]
const producer = new Producer({ // [!code ++]
clientId: 'my-app', // [!code ++]
bootstrapBrokers: ['localhost:9092'], // [!code ++]
serializers: stringSerializers // [!code ++]
}) // [!code ++]

await producer.connect() // [!code --]
await producer.send({
topic: 'events', // [!code --]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is removed in migration but doesn't seem to be introduced anywhere else. whats the equivalent of this in the replacement libraries?

messages: [{ key: 'event-1', value: 'created' }]
})

await producer.disconnect() // [!code --]
await producer.close() // [!code ++]
```

## `@confluentinc/kafka-javascript`

[`@confluentinc/kafka-javascript`](https://github.com/confluentinc/confluent-kafka-javascript) is Confluent's client, backed by the native `librdkafka` library. Confluent was founded by [Kafka's](https://kafka.apache.org/) creators and is a major contributor to the Kafka project. Its KafkaJS-compatible API can make it a good choice for incremental migrations, but it has native binaries.

Example:

<!-- prettier-ignore -->
```js
const { Kafka } = require('kafkajs') // [!code --]
const { Kafka } = require('@confluentinc/kafka-javascript').KafkaJS // [!code ++]

const kafka = new Kafka({
clientId: 'my-app', // [!code --]
brokers: ['localhost:9092'] // [!code --]
kafkaJS: { // [!code ++]
clientId: 'my-app', // [!code ++]
brokers: ['localhost:9092'] // [!code ++]
} // [!code ++]
})
```
16 changes: 16 additions & 0 deletions manifests/preferred.json
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,12 @@
"replacements": ["jsx-ast-utils-x"],
"url": {"type": "e18e", "id": "jsx-ast-utils"}
},
"kafkajs": {
"type": "module",
"moduleName": "kafkajs",
"replacements": ["@platformatic/kafka", "@confluentinc/kafka-javascript"],
"url": {"type": "e18e", "id": "kafkajs"}
},
"lodash": {
"type": "module",
"moduleName": "lodash",
Expand Down Expand Up @@ -2810,6 +2816,11 @@
"type": "documented",
"replacementModule": "@11ty/gray-matter"
},
"@confluentinc/kafka-javascript": {
"id": "@confluentinc/kafka-javascript",
"type": "documented",
"replacementModule": "@confluentinc/kafka-javascript"
},
"@eslint-community/eslint-plugin-eslint-comments": {
"id": "@eslint-community/eslint-plugin-eslint-comments",
"type": "documented",
Expand Down Expand Up @@ -2850,6 +2861,11 @@
"type": "documented",
"replacementModule": "@placemarkio/tokml"
},
"@platformatic/kafka": {
"id": "@platformatic/kafka",
"type": "documented",
"replacementModule": "@platformatic/kafka"
},
"@vitest/eslint-plugin": {
"id": "@vitest/eslint-plugin",
"type": "documented",
Expand Down