Skip to content

rpoitras/StompBrokerJS

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Known Vulnerabilities GitHub issues

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
  • 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);
}, 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

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
[debug] function function(args) {} Debug function
[path] string "/stomp" Websocket path

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

About

NodeJS StompBroker

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%