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
- Authorization
- Acknowledgment
- Async send messages
- Transactions
- Composite Destinations
- Message selectors
- 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.
- 1.1.1 Unsubscribe on server, updated documentation, added events.
- 1.1.2 Binary data sending, updated documentation, allowed server name modification.
- 1.2.0 Added heartbeat.
var http = require("http");
var StompServer = require('stomp-broker-js');
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, headers);
});
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
- new StompServer(config)
- .onUnsubscribe() ⇒
boolean
- .subscribe(topic, [callback], headers) ⇒
string
- .unsubscribe(id) ⇒
boolean
- .send(topic, headers, body)
- .frameSerializer(frame) ⇒
MsgFrame
- .frameParser(frame) ⇒
MsgFrame
- "error"
- "connecting"
- "connected"
- "disconnected"
- "send"
- "subscribe"
- "unsubscribe"
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 |
headers | object |
Optional headers, used by client to provide a subscription ID (headers.id) |
Example
stompServer.subscribe("/test.data", function(msg, headers) {}, 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, can be Buffer object |
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 | |
[serverName] | string |
"STOMP-JS/" + VERSION |
Websocket server name |
[path] | string |
"/stomp" |
Websocket path |
[heartbeat] | array |
[10000, 10000] |
Heartbeat; read documentation to config according to your desire |
[heartbeatErrorMargin] | number |
1000 |
Heartbeat error margin; specify how strict server should be |
[debug] | function |
function(args) {} |
Debug function |
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