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

sand-amqp

v1.0.3

Published

Sand AMQP Library

Downloads

6

Readme

sand-amqp

This package provides AMQP integration for Sand applications. It wraps @sazze/amqp.

Installation

npm install --save sand-amqp

Usage

The Publisher and Consumer classes wrap their respective objects from @sazze/amqp. They automatically handle connectivity upon instantiation, and clean disconnection on application shutdown. The ready event is raised when connectivity is established.

Publisher

To instantiate a new Publisher instance, call sand.amqp.startPublisher(config, name).

Configuration options are available here; they are defaulted by the amqp values in your application's config/amqp.js file.

If name is provided, the publisher will be available via the sand.amqp.publishers object.

In addition to the publisher options there is also autoConnect, which defaults to true and determines whether or not to auto connect on instantiation.

Consumer

To instantiate a new Consumer instance, call sand.amqp.startConsumer(config, name).

Configuration options are available here; they are defaulted by the amqp values in your application's config/amqp.js file. If a handler function is provided as an option, it is invoked when a message is received. handler may be a regular function or a generator function.

If name is provided, the consumer will be available via the sand.amqp.consumers object.

In addition to the consumer options, specific to this library there is also autoStart, which defaults to true and determines whether or not the consumer starts on instantiation. There is also runInSandContext which defaults to true. If TRUE then the handler function runs inside a sand context.

Autostarting

If autoStart is set in the configuration, sand-amqp will automatically instantiate any publisher and consumer configurations stored in the publisherDir and consumerDir directories. This is useful if you want publishers and consumers to automatically start and persist throughout the lifetime of your application.

publisherDir and consumerDir values should be relative to your Sand application path.

Example

This example Sand application will connect to the local AMQP instance and publish the string hello world to the demo exchange once per second.

config/amqp.js:

"use strict";

module.exports = {
  all: {
    amqp: {
      host: '127.0.0.1',
      port: 5672,
      user: 'guest',
      password: 'guest',
      vhost: '/',
      ssl: {
        enable: false
      }
    }
  }
};

app.js:

"use strict";

const Sand = require('sand');
const amqp = require('sand-amqp');

new Sand({ appPath: __dirname })
  .use(amqp)
  .start(function*() {
    sand.amqp.startConsumer({
      exchange: {
        name: 'demo',
        type: 'direct'
      },
      handler: (msg) => console.log(msg)
    });

    let publisher = sand.amqp.startPublisher({
      exchange: {
        name: 'demo',
        type: 'direct'
      }
    });

    setInterval(function() {
      publisher.publish('hello world');
    }, 1000);
  });

Output:

hello world
hello world
hello world

Testing

Note: A running AMQP instance is required for tests to pass. You may need to adjust test/fixtures/config/test.js for your environment.

To test, run npm test from the project root directory.

License

ISC