Convert Figma logo to code with AI

jmesnil logostomp-websocket

Stomp client for Web browsers and node.js apps

1,445
587
1,445
88

Top Related Projects

Spring Framework

Quick Overview

STOMP-WebSocket is a JavaScript library that implements the STOMP (Simple Text Oriented Messaging Protocol) over WebSocket. It allows web applications to communicate with message brokers using the STOMP protocol, enabling real-time messaging and pub/sub functionality in web browsers.

Pros

  • Easy integration with existing STOMP message brokers
  • Supports both browser and Node.js environments
  • Lightweight and has minimal dependencies
  • Provides a simple API for STOMP operations

Cons

  • Limited active development (last update was in 2019)
  • Lacks some advanced features found in newer messaging libraries
  • Documentation could be more comprehensive
  • May require additional setup for secure WebSocket connections (WSS)

Code Examples

  1. Connecting to a STOMP broker:
const client = Stomp.client('ws://localhost:15674/ws');
client.connect({}, function(frame) {
    console.log('Connected: ' + frame);
});
  1. Subscribing to a topic:
client.subscribe('/topic/messages', function(message) {
    console.log('Received message: ' + message.body);
});
  1. Sending a message:
client.send('/queue/test', {priority: 9}, 'Hello, STOMP');
  1. Disconnecting from the broker:
client.disconnect(function() {
    console.log('Disconnected');
});

Getting Started

  1. Include the STOMP-WebSocket library in your project:
<script src="https://cdn.jsdelivr.net/npm/@stomp/stompjs@5.0.0/bundles/stomp.umd.min.js"></script>
  1. Create a STOMP client and connect to a WebSocket endpoint:
const client = Stomp.client('ws://localhost:15674/ws');

client.connect({}, function(frame) {
    console.log('Connected: ' + frame);
    
    // Subscribe to a topic
    client.subscribe('/topic/messages', function(message) {
        console.log('Received: ' + message.body);
    });
    
    // Send a message
    client.send('/queue/test', {}, 'Hello, World!');
});
  1. Remember to handle disconnections and errors:
client.onStompError = function(frame) {
    console.log('Broker reported error: ' + frame.headers['message']);
    console.log('Additional details: ' + frame.body);
};

Competitor Comparisons

Spring Framework

Pros of Spring Framework

  • Comprehensive ecosystem with extensive features for enterprise Java development
  • Strong community support and regular updates
  • Integrates well with other Spring projects and third-party libraries

Cons of Spring Framework

  • Steeper learning curve due to its vast scope and complexity
  • Potentially heavier footprint for smaller applications
  • Configuration can be verbose, especially for simpler use cases

Code Comparison

STOMP WebSocket:

var client = Stomp.client('ws://localhost:8080/ws');
client.connect({}, function(frame) {
  client.subscribe('/topic/messages', function(message) {
    console.log('Received: ' + message.body);
  });
});

Spring Framework (using Spring WebSocket):

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/topic");
        config.setApplicationDestinationPrefixes("/app");
    }
}

While STOMP WebSocket provides a lightweight client-side implementation for STOMP over WebSocket, Spring Framework offers a more comprehensive solution with server-side support and integration with the broader Spring ecosystem. Spring's approach requires more setup but provides additional features and flexibility for complex applications.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

STOMP.js

This library provides a STOMP client for Web browser (using Web Sockets) or node.js applications (either using raw TCP sockets or Web Sockets).

Project Status

This project is no longer maintained (some context about this decision).

If you encounter bugs with it or need enhancements, you can fork it and modify it as the project is under the Apache License 2.0.

Web Browser support

The library file is located in lib/stomp.js (a minified version is available in lib/stomp.min.js). It does not require any dependency (except WebSocket support from the browser or an alternative to WebSocket!)

Online documentation describes the library API (including the annotated source code).

node.js support

Install the 'stompjs' module

$ npm install stompjs

In the node.js app, require the module with:

var Stomp = require('stompjs');

To connect to a STOMP broker over a TCP socket, use the Stomp.overTCP(host, port) method:

var client = Stomp.overTCP('localhost', 61613);

To connect to a STOMP broker over a WebSocket, use instead the Stomp.overWS(url) method:

var client = Stomp.overWS('ws://localhost:61614');

Development Requirements

For development (testing, building) the project requires node.js. This allows us to run tests without the browser continuously during development (see cake watch).

$ npm install

Building and Testing

Build Status

To build JavaScript from the CoffeeScript source code:

$ cake build

To run tests:

$ cake test

To continuously run tests on file changes:

$ cake watch

Browser Tests

  • Make sure you have a running STOMP broker which supports the WebSocket protocol (see the documentation)
  • Open in your web browser the project's test page
  • Check all tests pass

Use

The project contains examples for using stomp.js to send and receive STOMP messages from a server directly in the Web Browser or in a WebWorker.

Authors

NPM DownloadsLast 30 Days