Coder Social home page Coder Social logo

node-stomp-client's Introduction

Stomp Client

Build Status

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

Installation

npm install stomp-client

Super basic example

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

API

Queue Names

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.

Stomp = require('stomp-client')

Require returns a constructor for STOMP client instances.

For backwards compatibility, require('stomp-client').StompClient is also supported.

Stomp(address, port, user, pass, protocolVersion)

  • address: address to connect to, default is "127.0.0.1"
  • port: port to connect to, default is 61613
  • 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.

stomp.connect([callback, [errorCallback]])

Connect to the STOMP server. If the callbacks are provided, they will be attached on the 'connect' and 'error' event, respectively.

virtualhosts

If using virtualhosts to namespace your queues, you must pass a version header of '1.1' otherwise it is ignored.

stomp.disconnect(callback)

Disconnect from the STOMP server. The callback will be attached on the 'disconnect' event.

stomp.subscribe(queue, [headers,] callback)

  • queue: queue to subscribe to
  • headers: headers to add to the SUBSCRIBE message
  • callback: will be called with message body as first argument, and header object as the second argument

stomp.unsubscribe(queue, [headers])

  • queue: queue to unsubscribe from
  • headers: headers to add to the UNSUBSCRIBE message

stomp.publish(queue, message, [headers])

  • queue: queue to publish to
  • message: message to publish, a string or buffer
  • headers: headers to add to the PUBLISH message

Event: 'connect'

Emitted on successful connect to the STOMP server.

Event: 'disconnect'

Emitted on successful disconnnect from the STOMP server.

Also emitted when the server arbitrarily disconnects, which should be considered a bug.

Event: 'error'

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.

LICENSE

MIT

node-stomp-client's People

Contributors

easternbloc avatar sam-github avatar grenzr avatar russellhaering avatar kgoerlitz avatar jangie avatar blakmatrix avatar gknapp avatar tepafoo avatar

Watchers

James Cloos avatar Carl Glaysher avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.