npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

stompy

v1.5.0

Published

Stomp Client written against ActiveMQ

Downloads

40

Readme

stompy a node stomp client (unfinished)

Having had issues with other libraries in the past, random connection drops over a period of runtime with no reconnect for example, it seems fit to try a ground up rewrite.

Currently written for STOMP v1.1, the intent is to support all of this protocol, the following frame commands are unsupported at present:

  • RECEIPT
  • BEGIN
  • COMMIT
  • ABORT

#Usage Require the library, and create a client:

var stomp = require('stompy'),
    client = stomp.createClient();

In the createClient() method an options object can be passed, the defaults look like:

{
  host: 'localhost',
  port: 61613,
  retryOnClosed:true,
  heartbeat: {
    client: 5000,
    broker: 5000,
    grace: 2000
  }
}

N.B: In tests it seems unreliable to have heartbeat timeouts lower than 5 seconds.

###Publish To publish to a destination:

var stomp = require('stompy'),
    client = stomp.createClient();

client.publish('/queue/foo', 'bar');

Other headers for a message can be provided like so:

var stomp = require('stompy'),
client = stomp.createClient();

client.publish('/queue/foo', {persistent: true}, 'bar');

###Subscribing Subscribing to a destination is as simple as:

var stomp = require('stompy'),
    client = stomp.createClient();

client.subscribe('/queue/foo', function (msg) {
  console.info('/queue/foo:', msg);
});

It is a good practice to acknowledge messages from the broker, to perform this:

  • Provide the option as true to the subscribe function
  • Use the frame object passed back to your message handler to ack the message
var stomp = require('stompy'),
client = stomp.createClient();

client.subscribe('/queue/foo', { ack: true } function (msg, frame) {
  console.info('/queue/foo:', msg);
  frame.ack();
  //frame.nack();
});

Please note that nacking a message will likely not have the desired effect unless your messages are persistent.

There is also the facility to subscribe to the actual internal event upon an incoming message from the broker, could be useful if using the event pattern in your project whilst not incurring the extra network bandwith.

var stomp = require('stompy'),
client = stomp.createClient();

var sub client.subscribe('/queue/foo', function (msg) {
  console.info('/queue/foo:', msg);
});

client.subscribeToEvent(sub, function (msg) {
  // ...
});

###Unsubscribing Unsubscribing from a destination is just as easy:

var stomp = require('stompy'),
client = stomp.createClient();

var sub = client.subscribe('/queue/foo', function (msg) {
  console.info('/queue/foo:', msg);

  client.unsubscribe(sub);
});

##Events ###error Occurs when an error occurs inside the client, for example the end of a pipe, connection refused, etc.

var stomp = require('stompy'),
client = stomp.createClient();

client.on('error', function (err) {
  //do something...
});

###transportError Occurs when the broker sends an error frame.

var stomp = require('stompy'),
client = stomp.createClient();

client.on('transportError', function (frame) {
  //do something...
});

###lateheartbeat Occurs when the broker is late on a heartbeat.

var stomp = require('stompy'),
client = stomp.createClient();

client.on('lateheartbeat', function (frame) {
  //do something...
});

###closed Occurs when the broken closed the connection. By default, a new connection is created, but you can disable this, with the property 'retryOnClosed' and set it to false. It will only try one time.