A node.js STOMP client. Props goes to Russell Haering for doing the initial legwork.
The following enhancements have been added:
- Unit tests
- Ability to support different protocol versions (1.0 or 1.1) - more work needed
- Inbound frame validation (required / regex'able header values)
- Support for UNSUBSCRIBE frames in client
- Ability to add custom headers to SUBSCRIBE/UNSUBSCRIBE frames
npm install stomp-client
var Stomp = require('stomp-client');
var destination = '/queue/someQueueName';
var client = new Stomp('127.0.0.1', 61613, 'user', 'pass');
client.connect(function(sessionId) {
client.subscribe(destination, function(body, headers) {
console.log('This is the body of a message on the subscribed queue:', body);
});
client.publish(destination, 'Oh herrow');
});
The client comes in two forms, a standard or secure client. The example below is
using the standard client. To use the secure client simply change
StompClient
to SecureStompClient
The meaning of queue names is not defined by the STOMP spec, but by the Broker.
However, with ActiveMQ, they should begin with "/queue/"
or with "/topic/"
, see
STOMP1.0 for
more detail.
Require returns a constructor for STOMP client instances.
For backwards compatibility, require('stomp-client').StompClient
is also
supported.
address
: address to connect to, default is"127.0.0.1"
port
: port to connect to, default is61613
user
: user to authenticate as, default is""
pass
: password to authenticate with, default is""
protocolVersion
: see below, defaults to"1.0"
Protocol version negotiation is not currently supported and version "1.0"
is
the only supported version.
Connect to the STOMP server. If the callbacks are provided, they will be
attached on the 'connect'
and 'error'
event, respectively.
If using virtualhosts to namespace your queues, you must pass a version
header of '1.1' otherwise it is ignored.
Disconnect from the STOMP server. The callback will be attached on the
'disconnect'
event.
queue
: queue to subscribe toheaders
: headers to add to the SUBSCRIBE messagecallback
: will be called with message body as first argument, and header object as the second argument
queue
: queue to unsubscribe fromheaders
: headers to add to the UNSUBSCRIBE message
queue
: queue to publish tomessage
: message to publish, a string or bufferheaders
: headers to add to the PUBLISH message
Emitted on successful connect to the STOMP server.
Emitted on successful disconnnect from the STOMP server.
Also emitted when the server arbitrarily disconnects, which should be considered a bug.
Emitted on an error at either the TCP or STOMP protocol layer. An Error object
will be passed. All error objects have a .message
property, STOMP protocol
errors may also have a .details
property.