STOMP.js is a fully-fledged STOMP over WebSocket library for browsers and Node.js, providing seamless integration with STOMP protocol-compliant messaging brokers.
- Introduction
- Features
- Getting Started
- Documentation
- Upgrading
- Usage with RxJS
- TypeScript Support
- Changelog
- Contributing
- Authors
- License
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.
- 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
This section provides a quick guide to integrating STOMP.js into your browser or Node.js application.
To use STOMP.js in a browser:
-
Add the following in your HTML file:
<script type="importmap"> { "imports": { "@stomp/stompjs": "https://ga.jspm.io/npm:@stomp/[email protected]/esm6/index.js" } } </script> <script async src="https://ga.jspm.io/npm:[email protected]/dist/es-module-shims.js" crossorigin="anonymous" ></script>
-
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();
To use STOMP.js in a Node.js environment:
-
Install the package:
npm install @stomp/stompjs ws
-
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();
Comprehensive documentation can be found at: STOMP.js Documentation
- API Overview: API Docs (latest)
- Usage Guide: Guide to Using STOMP.js
- Feature Guides: Explore additional guides at https://stomp-js.github.io/
If you are updating from an older version of STOMP.js, review the Upgrading Guide for any required changes.
Rx-Stomp builds upon this library, exposing all its features as RxJS Observables, enabling reactive programming patterns.
STOMP.js includes built-in TypeScript definitions, eliminating the need for external type definition files. Begin coding with TypeScript out-of-the-box!
Visit the Change Log for information about changes, improvements, and fixes in recent releases.
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!
This library is made possible by these amazing contributors:
- Deepak Kumar
- Astha Deep
- Dillon Sellars
- Jimi Charalampidis
- Raul
- Dimitar Georgiev
- Genadi
- Bobohuochai
- Sailai
- Harsh Deep
- Nikos Epping
- Tom Pachtner
- David Nussio
- Camille Drapier
- chai min
- umsungjun
- tomek3e
- Samuel Yinger
This library is originally based on stompjs by Jeff Mesnil with enhancements and bug fixes from Jeff Lindsay and Vanessa Williams.
Licensed under the Apache-2.0 License. See the LICENSE file for details.