UNPKG

4.67 kBMarkdownView Raw
1# STOMP.js
2
3[![Firefox, Chrome](https://github.com/stomp-js/stompjs/actions/workflows/linux.yml/badge.svg?branch=develop)](https://github.com/stomp-js/stompjs/actions/workflows/linux.yml)
4[![Safari, Edge](https://github.com/stomp-js/stompjs/actions/workflows/osx.yml/badge.svg?branch=develop)](https://github.com/stomp-js/stompjs/actions/workflows/osx.yml)
5[![NodeJS Test](https://github.com/stomp-js/stompjs/actions/workflows/node-js.yml/badge.svg?branch=develop)](https://github.com/stomp-js/stompjs/actions/workflows/node-js.yml)
6[![API docs refresh](https://github.com/stomp-js/stompjs/actions/workflows/docs-refresh.yml/badge.svg?branch=develop)](https://github.com/stomp-js/stompjs/actions/workflows/docs-refresh.yml)
7
8This library provides a STOMP over WebSocket client for Web browser and node.js applications.
9
10Please visit https://stomp-js.github.io/ for guides, FAQs and API docs.
11
12# Introduction
13
14This library allows you to connect to a STOMP broker over WebSocket. This library
15supports complete STOMP specifications including all current protocol variants. Most
16popular messaging brokers support STOMP and STOMP over WebSockets out-of-the-box
17or using plugins.
18
19## Features
20
21- Simple API to interact with the Stomp protocol
22- Support for v1.2, v1.1 and v1.0 of the Stomp protocol
23- Support for fallback options in case of WebSocket unavailable
24- Browser and Node.js support
25- Option to use STOMP over TCP
26- Binary payload support
27
28## Usage
29
30### Browser
31
32```html
33<!--
34 JSPM Generator Import Map
35 Edit URL: https://generator.jspm.io/#U2NgYGBkDM0rySzJSU1hcCguyc8t0AeTWcUO5noGega6SakliaYAYTzJAykA
36 -->
37<script type="importmap">
38 {
39 "imports": {
40 "@stomp/stompjs": "https://ga.jspm.io/npm:@stomp/stompjs@7.0.0/esm6/index.js"
41 }
42 }
43</script>
44
45<!-- ES Module Shims: Import maps polyfill for modules browsers without import maps support (all except Chrome 89+) -->
46<script
47 async
48 src="https://ga.jspm.io/npm:es-module-shims@1.5.1/dist/es-module-shims.js"
49 crossorigin="anonymous"
50></script>
51
52<script type="module">
53 import { Client } from '@stomp/stompjs';
54
55 const client = new Client({
56 brokerURL: 'ws://localhost:15674/ws',
57 onConnect: () => {
58 client.subscribe('/topic/test01', message =>
59 console.log(`Received: ${message.body}`)
60 );
61 client.publish({ destination: '/topic/test01', body: 'First Message' });
62 },
63 });
64
65 client.activate();
66</script>
67```
68
69### NodeJS
70
71```bash
72$ npm install @stomp/stompjs ws
73```
74
75```javascript
76import { Client } from '@stomp/stompjs';
77
78import { WebSocket } from 'ws';
79Object.assign(global, { WebSocket });
80
81const client = new Client({
82 brokerURL: 'ws://localhost:15674/ws',
83 onConnect: () => {
84 client.subscribe('/topic/test01', message =>
85 console.log(`Received: ${message.body}`)
86 );
87 client.publish({ destination: '/topic/test01', body: 'First Message' });
88 },
89});
90
91client.activate();
92```
93
94## Further information
95
96The API documentation is hosted as GitHub pages for the StompJS family of libraries.
97You may head straight to the https://stomp-js.github.io/api-docs/latest/
98
99This library comes with detailed usage instructions. Please find it at
100[Usage instructions](https://stomp-js.github.io/guide/stompjs/using-stompjs-v5.html).
101Check out other guides at https://stomp-js.github.io/.
102
103There is quite detailed API documentation,
104you should start at https://stomp-js.github.io/api-docs/latest/classes/Client.html.
105
106## Upgrading
107
108if you were using an older version of this library, you would need to make changes
109to your code. Head to
110[Upgrading](https://stomp-js.github.io/#upgrading).
111
112## Usage with RxJS
113
114https://github.com/stomp-js/rx-stomp is based on this library and exposes the entire functionality
115offered by this library as RxJS Observables.
116
117## TypeScript definitions
118
119The npm package includes TypeScript definitions, so there is no need to install it separately.
120
121## Change-log
122
123Please visit [Change Log](Change-log.md).
124
125## Contributing
126
127If you want to understand the code, develop, or contribute. Please visit
128[How to contribute](Contribute.md).
129
130## Authors
131
132- [Jeff Mesnil](http://jmesnil.net/)
133- [Jeff Lindsay](http://github.com/progrium)
134- [Vanessa Williams](http://github.com/fridgebuzz)
135- [Deepak Kumar](https://github.com/kum-deepak)
136- [Astha Deep](https://github.com/astha183)
137- [Dillon Sellars](https://github.com/dillon-sellars)
138- [Jimi Charalampidis](https://github.com/jimic)
139- [Raul](https://github.com/rulonder)
140- [Dimitar Georgiev](https://github.com/iMitaka)
141- [Genadi](https://github.com/genadis)
142- [Bobohuochai](https://github.com/bobohuochai)
143- [Sailai](https://github.com/sailai)
144
145## License
146
147[License](LICENSE) - Apache-2.0