Registry / database / rabbitmq-stream-js-client

rabbitmq-stream-js-client

JSON →
library1.0.0jsnpmunverified

This library provides a client for the RabbitMQ stream protocol, enabling JavaScript and TypeScript applications to interact with RabbitMQ Streams. Designed for high-throughput, low-latency messaging, it facilitates publishing and consuming messages with advanced features like super streams, deduplication, and single active consumers. The current stable version is 1.0.0, released in April 2024. The project exhibits an active release cadence with frequent updates and bug fixes, indicated by multiple minor and patch releases leading up to 1.0.0, addressing features like external authentication, SSL options, and enhanced connection management. Key differentiators include its native support for RabbitMQ's stream protocol, enabling advanced features for horizontal scaling, message deduplication for exactly-once semantics, and single active consumer patterns for workload distribution. It also provides robust connection handling, including explicit connection pooling and automatic reconnect mechanisms, making it suitable for high-reliability, distributed systems.

npm install rabbitmq-stream-js-client
INSTALL
IMPORT
SIG · RABBITMQ-STREAM-JS
R
rabbitmq-stream-js-client
databasejavascriptv1.0.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

connect
✓ import { connect } from 'rabbitmq-stream-js-client';
✗ const rabbit = require('rabbitmq-stream-js-client'); const client = await rabbit.connect(...);
For modern TypeScript and ESM projects, prefer named imports. The 'require' style is shown in older examples but may cause issues with type inference or bundlers.
StreamClient
✓ import { StreamClient } from 'rabbitmq-stream-js-client';
While 'connect' is the primary entry point, importing StreamClient is useful for type annotations or if you need to extend its functionality.
Publisher
✓ import { Publisher } from 'rabbitmq-stream-js-client';
Publisher instances are typically created via `client.declarePublisher()`, but the type can be imported for explicit typing.

Demonstrates connecting to RabbitMQ Stream, declaring a stream, publishing a message, and consuming it.

import { connect } from 'rabbitmq-stream-js-client'; import { Buffer } from 'buffer'; // Node.js Buffer is needed for message content async function runRabbitStreamExample() { const client = await connect({ hostname: process.env.RABBITMQ_HOST ?? 'localhost', port: parseInt(process.env.RABBITMQ_STREAM_PORT ?? '5552', 10), username: process.env.RABBITMQ_USERNAME ?? 'rabbit', password: process.env.RABBITMQ_PASSWORD ?? 'rabbit', vhost: process.env.RABBITMQ_VHOST ?? '/', }); const streamName = 'my-first-stream'; // Declare a stream (if it doesn't exist, it will be created) await client.declareStream({ stream: streamName }); const publisher = await client.declarePublisher({ stream: streamName, publisherRef: 'my-publisher-ref', }); const messageContent = Buffer.from('Hello, RabbitMQ Stream!'); await publisher.send(messageContent); console.log('Message published:', messageContent.toString()); const consumer = await client.createConsumer( { stream: streamName, consumerRef: 'my-consumer-ref', offset: 'first', }, (message) => { console.log('Message consumed:', message.getData().toString()); consumer.close(); // Close consumer after first message for this example } ); // Give some time for the consumer to receive the message await new Promise(resolve => setTimeout(resolve, 1000)); await publisher.close(); await client.close(); console.log('Client and publisher closed.'); } runRabbitStreamExample().catch(console.error);
Debug
Known issues
breakingThe `Connection closed` listener is no longer called by the client. Applications relying on this specific event for connection state management will need to adjust.
fix
Review connection management strategies. The client now handles auto-reconnecting internally. Refer to updated README examples for managing connection stability, e.g., how to handle auto-reconnects as shown in the v0.4.0 changelog.
affects: >=0.4.0
gotchaWhen using message deduplication with `publisherRef` or `publishingId`, it is solely the user's responsibility to guarantee the uniqueness and incremental order of these IDs. RabbitMQ Stream does not enforce or manage these across producers, which can lead to message loss or unexpected deduplication if not handled correctly.
fix
Implement a robust strategy for generating unique and monotonic `publishingId`s, potentially using a shared sequence generator or UUIDs with external storage for persistence across application restarts.
affects: >=0.5.0
gotchaThe `ca` parameter for SSL/TLS connections is optional. If not provided, the client will rely on the system's default CAs or accept self-signed certificates depending on Node.js configuration, which might be a security risk in production environments.
fix
Always provide the `ca` (Certificate Authority) certificate when connecting through TLS/SSL in production environments to ensure proper certificate chain validation and secure communication.
affects: >=0.6.2
breakingInternal refactoring around connection pooling (e.g., connection pool as an instance, managing connections inside the pool) in v0.6.2 might affect applications that previously attempted to interfere with or manage underlying connections directly.
fix
Rely on the client's public API for connection management. Avoid direct manipulation of internal connection objects, as the library now explicitly manages connection lifecycles within its pool.
affects: >=0.6.2
Errors
Common errors & fixes
Error: Code 83 (NOT_SUPPORTED_FORMAT) when message is published using amqplib
Messages published via the AMQP 0-9-1 protocol (e.g., using `amqplib`) might not be compatible with the RabbitMQ Stream protocol due to differences in message formatting and properties.
fix
Ensure all messages intended for RabbitMQ Streams are published using `rabbitmq-stream-js-client`. Do not mix publishing messages to streams using `amqplib` or other AMQP 0-9-1 clients, as the stream protocol has its own specific message structure.
Error: connect ECONNREFUSED 127.0.0.1:5552
The client could not establish a connection to the RabbitMQ Stream server. This typically means the server is not running, is not listening on the specified host/port, or a firewall is blocking the connection.
fix
Verify that your RabbitMQ server is running and the Stream plugin is enabled. Check the `hostname` and `port` (default 5552 for streams) in your connection configuration. Ensure no firewall rules are preventing the connection.
TypeError: rabbit.connect is not a function
You are likely attempting to use a CommonJS `require` syntax in a TypeScript or ESM project without correctly destructuring the module's named exports.
fix
Use ESM named imports: `import { connect } from 'rabbitmq-stream-js-client';`. If you must use `require`, destructure it: `const { connect } = require('rabbitmq-stream-js-client');`.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
18
OpenAI (training)
1
Resources
rabbitmq-stream-js-client — npm install rabbitmq-stream-js-client · libregistry