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

vinyl-amqp

v0.11.0

Published

Presents an AMQP queue as either a source or destination stream of Vinyl objects.

Downloads

42

Readme

vinyl-amqp

Presents an AMQP queue as either a source or destination stream of Vinyl objects.

wercker status Dependency Status

Example

dest

To send a Vinyl file to a queue, use the dest() function, with a queue name as the parameter:

var gulp = require('gulp');
var es = require('event-stream');
var File = require('vinyl');
var amqp = require('vinyl-amqp');

gulp.task('trigger', function() {
  return es.readArray([{hello: 'world'}])
    .pipe(es.map(function(obj, cb) {
      var file = new File({});
      file.contents = new Buffer(JSON.stringify(obj));

      cb(null, file);
    }))
    .pipe(amqp.dest('hello-world-test'))
    .on('waiting', function() {
      console.log('Waiting...');
    })
    .on('queued', function(flag) {
      console.log('Queued');
    });
});

Gulp will exit after sending all of the data to the queue. The queued event is fired when an item has been completely queued. This is usually the case, since the batch size -- which determines how many items are needed before waiting items are pushed to the queue -- is set to one by default. However, it's possible to send more than one item in a batch by setting options in the dest() function call:

    .pipe(amqp.dest('hello-world-test', {batchSize: 10}))

The waiting event is provided to indicate that an item is waiting for the batch total to be reached. This is described in more detail in the amqp-sqs module.

src

To read from the queue some other process (perhaps on another machine) simply uses the src() function, again with a queue name:

gulp.task('action', function() {
  return amqp.src('hello-world-test')
    .pipe(es.map(function(file, cb) {
      console.log('received:', file.contents.toString());
    }))
    .pipe(process.stdout);
});

Note that in this case Gulp does not exit but continues to poll the queue. The frequency of the polling defaults to 5 minutes, which is set in the amqp-sqs module. This can be overridden by providing a configuration file, with a value such as this:

amqp:
  subscribe:
    pollInterval: 0.25

This will set the poll to be a quarter of a minute, or 15 seconds.

More control will be provided over this behaviour in the future, such as allowing the stream to close if the queue is empty, setting the poll frequency in the src() function, and so on.

Checking the Queue Size

To get the count of the number of messages in the queue, set getMessageCount to true in the options parameter. Only the count will be returned, i.e., no messages will be read from the queue. For example:

gulp.task('count', function() {
  return amqp.src('hello-world-test', {getMessageCount: true})
    .pipe(es.map(function(file, cb) {
      console.log('message count:', file.contents.toString());
    }))
    .pipe(process.stdout);
});