Registry / messaging / webstomp-obs

webstomp-obs

JSON →
library1.5.0jsnpmunverified

A STOMP client for Web browsers and Node.js using RxJS Observables, providing a reactive approach to WebSocket messaging. Current stable version: 1.5.0. It forks the popular webstomp-client library, reimplementing the API with Observables for automatic connection sharing, reconnection, and resubscription. Key differentiators include shared WebSocket connections among subscribers, automatic reconnection with configurable retries, and automatic disconnection when the last subscriber unsubscribes. Supports modern browsers and Node.js with pluggable WebSocket libraries. Released under MIT license. Primarily used with Angular or other RxJS-based applications.

npm install webstomp-obs
INSTALL
IMPORT
SIG · WEBSTOMP-OBS
W
webstomp-obs
messagingjavascriptv1.5.0
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 (webstompobs)
import webstompobs from 'webstomp-obs';
const webstompobs = require('webstomp-obs'); // Works in CJS, but ESM is preferred
Default import provides the main library object with client() and over() methods.
Client (TypeScript type)
import type { Client, IFrame } from 'webstomp-obs';
import { Client } from 'webstomp-obs'; // Will cause runtime error if used as value
For TypeScript users, import types using 'import type' to avoid runtime errors.
webstompobs.client
const client = webstompobs.client('ws://example.com/stomp');
This is the standard way to create a client in browser environments where WebSocket is global.
webstompobs.over
const client = webstompobs.over(() => new WebSocket('ws://example.com/stomp'));
const client = webstompobs.over('ws://example.com/stomp'); // over expects a function, not a URL
Use over() for Node.js or custom WebSocket implementations.

Creates a STOMP client, connects to a RabbitMQ Web-Stomp endpoint, subscribes to a queue, logs received messages, and sends a test message after 2 seconds.

import webstompobs from 'webstomp-obs'; import { Subject } from 'rxjs'; // Create a STOMP client connecting to RabbitMQ default Web-Stomp endpoint const client = webstompobs.client('ws://localhost:15674/ws'); // Connect using default login/passcode (guest/guest for RabbitMQ) const connection$ = client.connect('guest', 'guest'); // Subscribe to a queue const messages$ = new Subject(); connection$.subscribe({ next: (frame) => { console.log('Connected: ' + frame.headers['session']); // Subscribe to /queue/test client.subscribe('/queue/test', (msg) => { const body = msg.body; console.log('Received: ' + body); messages$.next(body); }); }, error: (err) => console.error('Connection error: ' + err), complete: () => console.log('Connection closed') }); // Send a message setTimeout(() => { client.send('/queue/test', 'Hello STOMP!', {}); }, 2000);
Debug
Known issues
gotchaThe client() function uses the global WebSocket object. In Node.js, you must use over() with a custom WebSocket implementation.
fix
Use webstompobs.over(() => new (require('ws'))('ws://...')) for Node.js.
affects: *
deprecatedThe APIs from the original stomp-websocket documentation may not fully match this library's Observable-based API.
fix
Refer to the library's own documentation or the source code for the correct method signatures.
affects: *
gotchaAutomatic reconnection uses exponential backoff. Setting maxConnectAttempt to -1 causes infinite retries, which may cause memory or connection leaks.
fix
Set a finite maxConnectAttempt or unsubscribe on component destroy to prevent resource leaks.
affects: *
gotchaBinary mode (binary: true) is experimental and may not work with all STOMP brokers.
fix
Stick to default text mode unless your broker explicitly supports binary STOMP frames.
affects: >=1.0.0
Errors
Common errors & fixes
Error: No WebSocket object found. Use webstompobs.over() instead of webstompobs.client() in Node.js.
Using client() in Node.js where WebSocket is not globally defined.
fix
Use webstompobs.over(() => new WebSocket('...')) with a WebSocket library like 'ws'.
TypeError: webstompobs.client is not a function
Importing the default export incorrectly or using a wrong import path.
fix
Use `import webstompobs from 'webstomp-obs'` (default import) or `const webstompobs = require('webstomp-obs')`.
Error: Connection lost, reconnecting... (infinite loop)
maxConnectAttempt set to -1 or the server keeps rejecting connections.
fix
Set maxConnectAttempt to a finite number (e.g., 10) and handle the error Observable appropriately.
Upgrade
Version history
1.5.0latest on npm
Audit
Dependencies
rxjsrequiredCore dependency for Observable-based API
Agent activity
25 hits · last 30 days
node
22
OpenAI (training)
1
Resources
webstomp-obs — npm install webstomp-obs · libregistry