/StompBrokerJS

NodeJS StompBroker

Primary LanguageJavaScriptMIT LicenseMIT

Travis Known Vulnerabilities bitHound bitHound Beerpay Paypal

StompBrokerJS

NodeJS StompBroker

This is simple NodeJs STOMP 1.1 broker for embedded usage.

Features

  • 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
  • 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.
  • 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.

Example

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

Classes

StompServerEventEmitter

Typedefs

ServerConfig : object

STOMP Server configuration

OnSubscribedMessageCallback : function

Subscription callback method

MsgFrame : object

Message frame

StompServer ⇐ EventEmitter

Kind: global class
Extends: EventEmitter

new StompServer(config)

Param Type Description
config ServerConfig Configuration for STOMP server

stompServer.onUnsubscribe() ⇒ boolean

Kind: instance method of StompServer

stompServer.subscribe(topic, [callback], headers) ⇒ string

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) {});

stompServer.unsubscribe(id) ⇒ boolean

Unsubscribe topic with subscription id

Kind: instance method of StompServer
Returns: boolean - Subscription is deleted

Param Type Description
id string Subscription id

stompServer.send(topic, headers, body)

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

"error"

Client error event

Kind: event emitted by StompServer

"connecting"

Client connecting event, emitted after socket is opened.

Kind: event emitted by StompServer
Properties

Name Type
sessionId string

"connected"

Client connected event, emitted after connection established and negotiated

Kind: event emitted by StompServer
Properties

Name Type
sessionId string
headers object

"disconnected"

Client disconnected event

Kind: event emitted by StompServer
Properties

Name Type
sessionId string

"send"

Event emitted when broker send message to subscribers

Kind: event emitted by StompServer
Properties

Name Type Description
dest string Destination
frame string Message frame

"subscribe"

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

"unsubscribe"

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

ServerConfig : object

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

OnSubscribedMessageCallback : 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

MsgFrame : object

Message frame

Kind: global typedef