1 | [![npm version](https://img.shields.io/npm/v/kafkajs?color=%2344cc11&label=stable)](https://www.npmjs.com/package/kafkajs) [![npm pre-release version](https://img.shields.io/npm/v/kafkajs/beta?label=pre-release)](https://www.npmjs.com/package/kafkajs) [![Build Status](https://dev.azure.com/tulios/kafkajs/_apis/build/status/tulios.kafkajs?branchName=master)](https://dev.azure.com/tulios/kafkajs/_build/latest?definitionId=2&branchName=master) [![Slack Channel](https://kafkajs-slackin.herokuapp.com/badge.svg)](https://kafkajs-slackin.herokuapp.com/)
|
2 | <br />
|
3 | <p align="center">
|
4 | <a href="https://kafka.js.org">
|
5 | <img src="https://raw.githubusercontent.com/tulios/kafkajs/master/logo/v2/kafkajs_circle.svg" alt="Logo" width="125" height="125">
|
6 | </a>
|
7 |
|
8 | <h3 align="center">KafkaJS</h3>
|
9 |
|
10 | <p align="center">
|
11 | A modern Apache Kafka® client for Node.js
|
12 | <br />
|
13 | <a href="https://kafka.js.org/"><strong>Get Started »</strong></a>
|
14 | <br />
|
15 | <br />
|
16 | <a href="https://kafka.js.org/docs/getting-started" target="_blank">Read the Docs</a>
|
17 | ·
|
18 | <a href="https://github.com/tulios/kafkajs/issues/new?assignees=&labels=&template=bug_report.md&title=">Report Bug</a>
|
19 | ·
|
20 | <a href="https://github.com/tulios/kafkajs/issues/new?assignees=&labels=&template=feature_request.md&title=">Request Feature</a>
|
21 | </p>
|
22 | </p>
|
23 |
|
24 | ## Table of Contents
|
25 |
|
26 | - [About the project](#about)
|
27 | - [Sponsors](#sponsorship)
|
28 | - [Features](#features)
|
29 | - [Getting Started](#getting-started)
|
30 | - [Usage](#usage)
|
31 | - [Contributing](#contributing)
|
32 | - [Help Wanted](#help-wanted)
|
33 | - [Contact](#contact)
|
34 | - [License](#license)
|
35 | - [Acknowledgements](#acknowledgements)
|
36 |
|
37 | ## <a name="about"></a> About the Project
|
38 |
|
39 | KafkaJS is a modern [Apache Kafka](https://kafka.apache.org/) client for Node.js. It is compatible with Kafka 0.10+ and offers native support for 0.11 features.
|
40 |
|
41 | <small>KAFKA is a registered trademark of The Apache Software Foundation and has been licensed for use by KafkaJS. KafkaJS has no affiliation with and is not endorsed by The Apache Software Foundation.</small>
|
42 |
|
43 | ## <a name="sponsorship"></a> Sponsors ❤️
|
44 |
|
45 | <p id="banner" align="center">
|
46 | <table>
|
47 | <tr>
|
48 | <td>
|
49 | <img src="https://raw.githubusercontent.com/tulios/kafkajs/master/logo/sponsors/upstash.png" width="220" height="185" align="left" />
|
50 | <h3>Upstash: Serverless Kafka</h3>
|
51 | <ul>
|
52 | <li>True Serverless Kafka with per-request-pricing</li>
|
53 | <li>Managed Apache Kafka, works with all Kafka clients</li>
|
54 | <li>Built-in REST API designed for serverless and edge functions</li>
|
55 | <li><b><a href="https://upstash.com/?utm_source=kafkajs">Start for free in 30 seconds!</a></b></li>
|
56 | </ul>
|
57 | <img width="1000" height="0">
|
58 | </td>
|
59 | </tr>
|
60 | <tr>
|
61 | <td>
|
62 | <img src="https://raw.githubusercontent.com/tulios/kafkajs/master/logo/sponsors/kafkajs-devs.png" alt="Logo" width="220" height="185" align="left" />
|
63 | <h3>Get help directly from a KafkaJS developer</h3>
|
64 | <ul>
|
65 | <li>Become a Github Sponsor to have a video call with a KafkaJS developer</li>
|
66 | <li>Receive personalized support, validate ideas or accelerate your learning</li>
|
67 | <li>Save time and get productive sooner, while supporting KafkaJS!</li>
|
68 | <li><b><a href="https://github.com/sponsors/Nevon?frequency=one-time&sponsor=Nevon">See support options!</a></b></li>
|
69 | </ul>
|
70 | <img width="1000" height="0">
|
71 | </td>
|
72 | </tr>
|
73 | </table>
|
74 | </p>
|
75 |
|
76 | *To become a sponsor, [reach out in our Slack community](https://kafkajs-slackin.herokuapp.com/) to get in touch with one of the maintainers. Also consider becoming a Github Sponsor by following any of the links under "[Sponsor this project](https://github.com/tulios/kafkajs#sponsors)" in the sidebar.*
|
77 |
|
78 | ### <a name="features"></a> Features
|
79 |
|
80 | * Producer
|
81 | * Consumer groups with pause, resume, and seek
|
82 | * Transactional support for producers and consumers
|
83 | * Message headers
|
84 | * GZIP compression
|
85 | * Snappy, LZ4 and ZSTD compression through pluggable codecs
|
86 | * Plain, SSL and SASL_SSL implementations
|
87 | * Support for SCRAM-SHA-256 and SCRAM-SHA-512
|
88 | * Support for AWS IAM authentication
|
89 | * Admin client
|
90 |
|
91 | ### <a name="getting-started"></a> Getting Started
|
92 |
|
93 | ```sh
|
94 | npm install kafkajs
|
95 | # yarn add kafkajs
|
96 | ```
|
97 |
|
98 | #### <a name="usage"></a> Usage
|
99 | ```javascript
|
100 | const { Kafka } = require('kafkajs')
|
101 |
|
102 | const kafka = new Kafka({
|
103 | clientId: 'my-app',
|
104 | brokers: ['kafka1:9092', 'kafka2:9092']
|
105 | })
|
106 |
|
107 | const producer = kafka.producer()
|
108 | const consumer = kafka.consumer({ groupId: 'test-group' })
|
109 |
|
110 | const run = async () => {
|
111 | // Producing
|
112 | await producer.connect()
|
113 | await producer.send({
|
114 | topic: 'test-topic',
|
115 | messages: [
|
116 | { value: 'Hello KafkaJS user!' },
|
117 | ],
|
118 | })
|
119 |
|
120 | // Consuming
|
121 | await consumer.connect()
|
122 | await consumer.subscribe({ topic: 'test-topic', fromBeginning: true })
|
123 |
|
124 | await consumer.run({
|
125 | eachMessage: async ({ topic, partition, message }) => {
|
126 | console.log({
|
127 | partition,
|
128 | offset: message.offset,
|
129 | value: message.value.toString(),
|
130 | })
|
131 | },
|
132 | })
|
133 | }
|
134 |
|
135 | run().catch(console.error)
|
136 | ```
|
137 |
|
138 | Learn more about using [KafkaJS on the official site!](https://kafka.js.org)
|
139 |
|
140 | - [Getting Started](https://kafka.js.org/docs/getting-started)
|
141 | - [A Brief Intro to Kafka](https://kafka.js.org/docs/introduction)
|
142 | - [Configuring KafkaJS](https://kafka.js.org/docs/configuration)
|
143 | - [Example Producer](https://kafka.js.org/docs/producer-example)
|
144 | - [Example Consumer](https://kafka.js.org/docs/consumer-example)
|
145 |
|
146 | > _Read something on the website that didn't work with the latest stable version?_
|
147 | [Check the pre-release versions](https://kafka.js.org/docs/pre-releases) - the website is updated on every merge to master.
|
148 |
|
149 | ## <a name="contributing"></a> Contributing
|
150 |
|
151 | KafkaJS is an open-source project where development takes place in the open on GitHub. Although the project is maintained by a small group of dedicated volunteers, we are grateful to the community for bug fixes, feature development and other contributions.
|
152 |
|
153 | See [Developing KafkaJS](https://kafka.js.org/docs/contribution-guide) for information on how to run and develop KafkaJS.
|
154 |
|
155 | ### <a name="help-wanted"></a> Help wanted 🤝
|
156 |
|
157 | We welcome contributions to KafkaJS, but we also want to see a thriving third-party ecosystem. If you would like to create an open-source project that builds on top of KafkaJS, [please get in touch](https://kafkajs-slackin.herokuapp.com/) and we'd be happy to provide feedback and support.
|
158 |
|
159 | Here are some projects that we would like to build, but haven't yet been able to prioritize:
|
160 |
|
161 | * [Dead Letter Queue](https://eng.uber.com/reliable-reprocessing/) - Automatically reprocess messages
|
162 | * ✅ [Schema Registry](https://www.confluent.io/confluent-schema-registry/) - **[Now available!](https://www.npmjs.com/package/@kafkajs/confluent-schema-registry)** thanks to [@erikengervall](https://github.com/erikengervall)
|
163 | * [Metrics](https://prometheus.io/) - Integrate with the [instrumentation events](https://kafka.js.org/docs/instrumentation-events) to expose commonly used metrics
|
164 |
|
165 | ### <a name="contact"></a> Contact 💬
|
166 |
|
167 | [Join our Slack community](https://kafkajs-slackin.herokuapp.com/)
|
168 |
|
169 | ## <a name="license"></a> License
|
170 |
|
171 | See [LICENSE](https://github.com/tulios/kafkajs/blob/master/LICENSE) for more details.
|
172 |
|
173 | ### <a name="acknowledgements"></a> Acknowledgements
|
174 |
|
175 | * Thanks to [Sebastian Norde](https://github.com/sebastiannorde) for the V1 logo ❤️
|
176 | * Thanks to [Tracy (Tan Yun)](https://medium.com/@tanyuntracy) for the V2 logo ❤️
|
177 |
|
178 | <small>Apache Kafka and Kafka are either registered trademarks or trademarks of The Apache Software Foundation in the United States and other countries. KafkaJS has no affiliation with the Apache Software Foundation.</small>
|