@stomp/stompjs vs reconnecting-websocket vs sockjs-client vs stompjs vs webstomp-client
WebSocket and STOMP Libraries
@stomp/stompjsreconnecting-websocketsockjs-clientstompjswebstomp-clientSimilar Packages:

WebSocket and STOMP Libraries

WebSocket and STOMP libraries in JavaScript provide tools for real-time communication between clients and servers. These libraries enable bidirectional data exchange, allowing applications to send and receive messages instantly. WebSocket libraries focus on establishing and managing WebSocket connections, while STOMP (Simple Text Oriented Messaging Protocol) libraries build on top of WebSockets to provide a messaging protocol that supports features like topics, queues, and message acknowledgments. These libraries are essential for developing chat applications, live updates, online gaming, and other real-time web applications.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
@stomp/stompjs0882473 kB263 months agoApache-2.0
reconnecting-websocket01,312-686 years agoMIT
sockjs-client08,519700 kB30-MIT
stompjs01,447-8812 years agoApache-2.0
webstomp-client0298-238 years agoApache-2.0

Feature Comparison: @stomp/stompjs vs reconnecting-websocket vs sockjs-client vs stompjs vs webstomp-client

Protocol Support

  • @stomp/stompjs:

    @stomp/stompjs supports the STOMP protocol over WebSockets, providing a full-featured implementation with support for transactions, acknowledgments, and heartbeats. It is ideal for applications that require robust messaging capabilities and compliance with the STOMP specification.

  • reconnecting-websocket:

    reconnecting-websocket focuses on the WebSocket protocol, providing a simple client with automatic reconnection capabilities. It does not implement any messaging protocols, making it suitable for applications that handle their own message formatting and processing.

  • sockjs-client:

    sockjs-client provides a WebSocket emulation protocol with fallback options for environments where WebSockets are not supported. It ensures reliable real-time communication by automatically selecting the best available transport method, including XHR streaming, long polling, and iframe-based transports.

  • stompjs:

    stompjs implements the STOMP protocol over WebSockets, providing a lightweight client for sending and receiving messages. It is suitable for applications that need basic STOMP functionality without the overhead of advanced features.

  • webstomp-client:

    webstomp-client provides a modern implementation of the STOMP protocol over WebSockets, focusing on simplicity and performance. It is designed for applications that require efficient messaging with a clean API.

Reconnection

  • @stomp/stompjs:

    @stomp/stompjs includes built-in support for automatic reconnection with configurable retry intervals. It also supports heartbeats to detect and recover from lost connections, ensuring reliable communication in unstable network conditions.

  • reconnecting-websocket:

    reconnecting-websocket is specifically designed for automatic reconnection, with configurable parameters for retry delays, maximum attempts, and exponential backoff. It is lightweight and easy to integrate, making it ideal for applications that need reliable WebSocket connections.

  • sockjs-client:

    sockjs-client does not provide automatic reconnection out of the box, but it can be combined with other libraries or custom code to implement reconnection logic. Its primary focus is on providing fallback transports for real-time communication.

  • stompjs:

    stompjs does not include built-in reconnection logic, but it can be extended to support automatic reconnection. Developers need to implement their own reconnection strategies to handle lost connections.

  • webstomp-client:

    webstomp-client does not provide automatic reconnection, but its simple API makes it easy to implement custom reconnection logic. It is designed for applications that require efficient messaging and can handle connection management externally.

Fallback Support

  • @stomp/stompjs:

    @stomp/stompjs focuses on WebSocket communication and does not provide built-in fallback support for environments where WebSockets are unavailable. However, it can be used in conjunction with libraries like SockJS to provide fallback transports while maintaining STOMP functionality.

  • reconnecting-websocket:

    reconnecting-websocket does not provide fallback support for non-WebSocket environments. It is designed to work exclusively with WebSockets, relying on the browser's native WebSocket implementation for communication.

  • sockjs-client:

    sockjs-client is designed to provide fallback support for real-time communication in environments where WebSockets are not supported. It automatically selects the best available transport method, including XHR streaming, long polling, and iframe-based transports, ensuring reliable communication across a wide range of browsers and network conditions.

  • stompjs:

    stompjs focuses on STOMP over WebSockets and does not provide fallback support for non-WebSocket environments. It relies on the underlying WebSocket connection for communication, making it unsuitable for environments where WebSockets are unavailable.

  • webstomp-client:

    webstomp-client provides a modern STOMP client implementation over WebSockets but does not include fallback mechanisms for environments where WebSockets are not supported. It is designed for applications that can rely on native WebSocket support.

Ease of Use

  • @stomp/stompjs:

    @stomp/stompjs provides a comprehensive and well-documented API for working with STOMP over WebSockets. It includes examples and guides that make it easier for developers to implement messaging features, especially in applications that require advanced STOMP functionality.

  • reconnecting-websocket:

    reconnecting-websocket offers a simple and intuitive API for establishing WebSocket connections with automatic reconnection. Its lightweight design and clear documentation make it easy to integrate into projects with minimal effort.

  • sockjs-client:

    sockjs-client provides a straightforward API for establishing real-time communication with fallback support. Its documentation includes examples that help developers understand how to use the library effectively, especially in scenarios where WebSocket support is uncertain.

  • stompjs:

    stompjs offers a simple API for working with the STOMP protocol over WebSockets. It is easy to use for basic messaging tasks, but its documentation may lack depth compared to more modern libraries, which could lead to a steeper learning curve for advanced features.

  • webstomp-client:

    webstomp-client provides a clean and modern API for STOMP messaging over WebSockets. Its focus on simplicity and performance makes it easy to use, and it includes documentation that helps developers quickly understand how to implement messaging features.

Ease of Use: Code Examples

  • @stomp/stompjs:

    STOMP over WebSocket with @stomp/stompjs

    import { Client } from '@stomp/stompjs';
    const client = new Client({
      brokerURL: 'ws://localhost:8080/stomp',
      reconnectDelay: 5000,
      onConnect: () => {
        client.subscribe('/topic/messages', (message) => {
          console.log('Received:', message.body);
        });
        client.publish({ destination: '/app/chat', body: 'Hello, STOMP!' });
      },
    });
    client.activate();
    
  • reconnecting-websocket:

    WebSocket with Automatic Reconnection using reconnecting-websocket

    import ReconnectingWebSocket from 'reconnecting-websocket';
    const rws = new ReconnectingWebSocket('ws://localhost:8080/socket');
    rws.addEventListener('open', () => {
      console.log('Connected');
      rws.send('Hello, WebSocket!');
    });
    rws.addEventListener('message', (event) => {
      console.log('Received:', event.data);
    });
    
  • sockjs-client:

    Real-Time Communication with Fallbacks using sockjs-client

    import SockJS from 'sockjs-client';
    const sock = new SockJS('http://localhost:8080/sockjs');
    sock.onopen = () => {
      console.log('Connection opened');
      sock.send('Hello, SockJS!');
    };
    sock.onmessage = (e) => {
      console.log('Received:', e.data);
    };
    sock.onclose = () => {
      console.log('Connection closed');
    };
    
  • stompjs:

    Basic STOMP Messaging with stompjs

    import Stomp from 'stompjs';
    const client = Stomp.client('ws://localhost:8080/stomp');
    client.connect({}, () => {
      client.subscribe('/topic/messages', (message) => {
        console.log('Received:', message.body);
      });
      client.send('/app/chat', {}, 'Hello, STOMP!');
    });
    
  • webstomp-client:

    Efficient STOMP Messaging with webstomp-client

    import webstomp from 'webstomp-client';
    const socket = new WebSocket('ws://localhost:8080/webstomp');
    const client = webstomp.over(socket);
    client.connect({}, () => {
      client.subscribe('/topic/messages', (message) => {
        console.log('Received:', message.body);
      });
      client.send('/app/chat', 'Hello, WebSTOMP!');
    });
    

How to Choose: @stomp/stompjs vs reconnecting-websocket vs sockjs-client vs stompjs vs webstomp-client

  • @stomp/stompjs:

    Choose @stomp/stompjs if you need a modern, fully-featured STOMP client with support for WebSockets and fallback options. It is ideal for applications that require robust messaging capabilities, including support for transactions, acknowledgments, and heartbeats.

  • reconnecting-websocket:

    Choose reconnecting-websocket if you need a simple WebSocket client with automatic reconnection capabilities. It is lightweight and easy to use, making it suitable for applications that require reliable WebSocket connections without the overhead of a full messaging protocol.

  • sockjs-client:

    Choose sockjs-client if you need a WebSocket emulation library that provides fallback options for environments where WebSockets are not supported. It is useful for applications that need to ensure real-time communication across a wide range of browsers and network conditions.

  • stompjs:

    Choose stompjs if you need a lightweight STOMP client for WebSocket communication. It is suitable for applications that require basic STOMP functionality without the need for advanced features or extensive configuration.

  • webstomp-client:

    Choose webstomp-client if you need a modern STOMP client with a focus on simplicity and performance. It is designed for applications that require efficient messaging over WebSockets with a clean and easy-to-use API.

README for @stomp/stompjs

STOMP.js

Build Status - Firefox, Chrome Build Status - Safari, Edge Node.js Tests API Docs Refresh

STOMP.js is a fully-fledged STOMP over WebSocket library for browsers and Node.js, providing seamless integration with STOMP protocol-compliant messaging brokers.

Table of Contents

Introduction

This library enables clients to connect to STOMP brokers over WebSocket (or TCP). It fully implements the STOMP protocol specifications (v1.0, v1.1, and v1.2), making it compatible with any broker that supports STOMP or STOMP over WebSocket.

Popular brokers like RabbitMQ, ActiveMQ, and others provide support for STOMP and STOMP over WebSockets out-of-the-box.

Features

  • Simple and intuitive API for interacting with the STOMP protocol
  • Support for STOMP protocol versions: 1.2, 1.1, and 1.0
  • Support for fallback options when WebSocket is unavailable
  • Supports both browser and Node.js environments
  • Option to connect using STOMP over TCP
  • Full support for binary payloads
  • Compatible with RxJS for reactive programming

Getting Started

This section provides a quick guide to integrating STOMP.js into your browser or Node.js application.

Browser

To use STOMP.js in a browser:

  1. Add the following in your HTML file:

    <script type="importmap">
      {
        "imports": {
          "@stomp/stompjs": "https://ga.jspm.io/npm:@stomp/stompjs@7.0.0/esm6/index.js"
        }
      }
    </script>
    <script
      async
      src="https://ga.jspm.io/npm:es-module-shims@1.5.1/dist/es-module-shims.js"
      crossorigin="anonymous"
    ></script>
    
  2. Use the library:

    import { Client } from '@stomp/stompjs';
    
    const client = new Client({
      brokerURL: 'ws://localhost:15674/ws',
      onConnect: () => {
        client.subscribe('/topic/test01', message =>
          console.log(`Received: ${message.body}`)
        );
        client.publish({ destination: '/topic/test01', body: 'First Message' });
      },
    });
    
    client.activate();
    

Node.js

To use STOMP.js in a Node.js environment:

  1. Install the package:

    npm install @stomp/stompjs ws
    
  2. Use it in your application:

    import { Client } from '@stomp/stompjs';
    
    import { WebSocket } from 'ws';
    Object.assign(global, { WebSocket });
    
    const client = new Client({
      brokerURL: 'ws://localhost:15674/ws',
      onConnect: () => {
        client.subscribe('/topic/test01', message =>
          console.log(`Received: ${message.body}`)
        );
        client.publish({ destination: '/topic/test01', body: 'First Message' });
      },
    });
    
    client.activate();
    

Documentation

Comprehensive documentation can be found at: STOMP.js Documentation

Upgrading

If you are updating from an older version of STOMP.js, review the Upgrading Guide for any required changes.

Usage with RxJS

Rx-Stomp builds upon this library, exposing all its features as RxJS Observables, enabling reactive programming patterns.

TypeScript Support

STOMP.js includes built-in TypeScript definitions, eliminating the need for external type definition files. Begin coding with TypeScript out-of-the-box!

Changelog

Visit the Change Log for information about changes, improvements, and fixes in recent releases.

Contributing

Thinking of contributing to STOMP.js? Great! To get started:

  • Read the Contributing Guide for development instructions.
  • Report bugs or suggest features by creating an issue on GitHub.

We welcome contributions from the community!

Authors

This library is made possible by these amazing contributors:

This library is originally based on stompjs by Jeff Mesnil with enhancements and bug fixes from Jeff Lindsay and Vanessa Williams.

License

Licensed under the Apache-2.0 License. See the LICENSE file for details.