Registry / messaging / kafka-queue

kafka-queue

JSON →
library1.0.4jsnpmunverified

Lightweight Kafka wrapper for keyed-message queuing, targeting IoT systems where messages for the same device must be processed in order and by the same consumer. Built on no-kafka (v2.x), it automatically retries connections and supports configurable key fields for partitioning. Version 1.0.4 is the current stable release; development appears to be minimal with no recent updates. Differentiators include a simplified consumer callback that handles commits automatically, and an optional explicit commit pattern.

npm install kafka-queue
INSTALL
IMPORT
SIG · KAFKA-QUEUE
K
kafka-queue
messagingjavascriptv1.0.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const Q = require('kafka-queue')(config);
import Q from 'kafka-queue';
Package does not export ES modules; only CommonJS require is supported.
producer
const Q = require('kafka-queue')(config); Q.producer.connect(...);
Access via returned object's `producer` property.
consumer
const Q = require('kafka-queue')(config); Q.consumer.connect(queueName, groupId, handler);
import { consumer } from 'kafka-queue';
Must instantiate via the factory; direct import of consumer is unsupported.

Connects a producer and consumer to a Kafka broker, demonstrating basic enqueue and dequeue with keyed messages.

const config = { keyField: 'deviceId', connectionString: process.env.KAFKA_BROKER ?? 'localhost:9092', logger: { logLevel: 1 } }; const Q = require('kafka-queue')(config); // Producer Q.producer.connect((err) => { if (err) return console.error('Producer connect error:', err); Q.producer.send('my-queue', { deviceId: 'd1', payload: 'hello' }, (err) => { if (err) console.error('Send error:', err); console.log('Message sent'); }); }); // Consumer Q.consumer.connect('my-queue', 'my-group', (message, cb) => { console.log('Received:', JSON.stringify(message.msg)); cb(); // commit offset });
Debug
Known issues
gotchaNo automatic reconnection on consumer disconnect; broker or partition leadership changes may cause consumer to hang silently.
fix
Monitor consumer connection health and re-create consumer on failure.
affects: <=1.0.4
gotchaGroupId override behavior: explicitly passing groupId to consumer.connect() overrides config.groupId completely; if not passed, config.groupId must be set or connection fails.
fix
Always provide groupId explicitly to avoid confusion.
affects: <=1.0.4
deprecatedThe underlying no-kafka library is unmaintained and incompatible with newer Kafka versions (0.11+). No security patches.
fix
Migrate to a maintained Kafka client like kafka-node or kafkajs.
affects: <=1.0.4
gotchaConfig logger.logLevel: 1 means only errors; 2 for warnings, 3 for info. Missing or invalid values may suppress helpful diagnostics.
fix
Set logLevel to 3 during development for visibility.
affects: <=1.0.4
gotchaconsumer.commit() must be called with the 'handle' from the message object. Incorrect handle values cause silent failures in offset commits.
fix
Always use message.handle directly; never construct it manually.
affects: <=1.0.4
Errors
Common errors & fixes
TypeError: Q.producer is undefined
The factory function returns an object with producer/consumer only after a successful connect? Actually no—the factory always returns the object, but producer.connect must be called before using producer.send.
fix
Call Q.producer.connect(callback) before Q.producer.send().
Error: connect ECONNREFUSED 192.168.99.103:9092
Kafka broker is not running or the connection string is incorrect.
fix
Verify broker address and port; ensure Kafka is started and accessible.
Error: GroupId not set
No groupId provided in config or as argument to consumer.connect().
fix
Pass groupId to consumer.connect() or set config.groupId.
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies
no-kafkarequiredCore Kafka client used for all broker interactions
Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
kafka-queue — npm install kafka-queue · libregistry