NodeJS StompBroker
This is simple NodeJs STOMP 1.1 broker for embedded usage.
- Destination wildcards
- . is used to separate names in a path
- * is used to mach any name in a path
- ** is used to recursively match path names
#TODO
- Authorization
- Heartbeat
- Acknowledgment
- Async send messages
- Transactions
- Composite Destinations
- Message selectors
#Changelog
- 0.1.0 First working version.
- 0.1.1 Added wildcards to destination, change subscribe method [no backward compatibility]
- 0.1.2 Bug fixes, changed websocket library, updated documentation.
- 0.1.3 Unsubscribe on server, updated documentation, added events.
#Example
var http = require("http");
var StompServer = require('stompServer');
var server = http.createServer();
var stompServer = new StompServer({server: server});
server.listen(61614);
stompServer.subscribe("/**", function(msg, headers) {
var topic = headers.destination;
console.log(topic, "->", msg);
});
stompServer.send('/test', {}, 'testMsg');#Documentation
- StompServer ⇐
EventEmitter
- ServerConfig :
object STOMP Server configuration
- OnSubscribedMessageCallback :
function Subscription callback method
- MsgFrame :
object Message frame
Kind: global class
Extends: EventEmitter
- StompServer ⇐
EventEmitter
| Param | Type | Description |
|---|---|---|
| config | ServerConfig |
Configuration for STOMP server |
Kind: instance method of StompServer
Subsribe topic
Kind: instance method of StompServer
Returns: string - Subscription id, when message is received event with this id is emitted
| Param | Type | Description |
|---|---|---|
| topic | string |
Subscribed destination, wildcard is supported |
| [callback] | OnSubscribedMessageCallback |
Callback function |
Example
stompServer.subscribe("/test.data", function(msg, headers) {});
//or alternative
var subs_id = stompServer.subscribe("/test.data");
stompServer.on(subs_id, function(msg, headers) {});Unsubscribe topic with subscription id
Kind: instance method of StompServer
Returns: boolean - Subscription is deleted
| Param | Type | Description |
|---|---|---|
| id | string |
Subscription id |
Send message to topic
Kind: instance method of StompServer
| Param | Type | Description |
|---|---|---|
| topic | string |
Destination for message |
| headers | object |
Message headers |
| body | string |
Message body |
stompServer.frameSerializer(frame) ⇒ MsgFrame
Serialize frame to string for send
Kind: instance method of StompServer
Returns: MsgFrame - modified frame
| Param | Type | Description |
|---|---|---|
| frame | MsgFrame |
Message frame |
stompServer.frameParser(frame) ⇒ MsgFrame
Parse frame to object for reading
Kind: instance method of StompServer
Returns: MsgFrame - modified frame
| Param | Type | Description |
|---|---|---|
| frame | MsgFrame |
Message frame |
Client error event
Kind: event emitted by StompServer
Client connecting event, emitted after socket is opened.
Kind: event emitted by StompServer
Properties
| Name | Type |
|---|---|
| sessionId | string |
Client connected event, emitted after connection established and negotiated
Kind: event emitted by StompServer
Properties
| Name | Type |
|---|---|
| sessionId | string |
| headers | object |
Client disconnected event
Kind: event emitted by StompServer
Properties
| Name | Type |
|---|---|
| sessionId | string |
Event emitted when broker send message to subscribers
Kind: event emitted by StompServer
Properties
| Name | Type | Description |
|---|---|---|
| dest | string |
Destination |
| frame | string |
Message frame |
Client subscribe event, emitted when client subscribe topic
Kind: event emitted by StompServer
Properties
| Name | Type | Description |
|---|---|---|
| id | string |
Subscription id |
| sessionId | string |
Socket session id |
| topic | string |
Destination topic |
| tokens | Array.<string> |
Tokenized topic |
| socket | object |
Connected socket |
Client subscribe event, emitted when client unsubscribe topic
Kind: event emitted by StompServer
Properties
| Name | Type | Description |
|---|---|---|
| id | string |
Subscription id |
| sessionId | string |
Socket session id |
| topic | string |
Destination topic |
| tokens | Array.<string> |
Tokenized topic |
| socket | object |
Connected socket |
STOMP Server configuration
Kind: global typedef
| Param | Type | Default | Description |
|---|---|---|---|
| server | http.Server |
Http server reference | |
| [debug] | function |
function(args) {} |
Debug function |
| [path] | string |
"/stomp" |
Websocket path |
Subscription callback method
Kind: global typedef
| Param | Type | Description |
|---|---|---|
| msg | string |
Message body |
| headers | object |
Message headers |
| headers.destination | string |
Message destination |
| headers.subscription | string |
Id of subscription |
| headers.message-id | string |
Id of message |
| headers.content-type | string |
Content type |
| headers.content-length | string |
Content length |
Message frame
Kind: global typedef