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

akx-mq

v0.1.1

Published

This is a small library to handle rabbitmq messages. Mostly a wrapper.

Downloads

2

Readme

AkxMQ

================================ A wrapper around '''amqplib''' to handle retries, adding bulk consumers, and connect style middleware.

#Installation

npm install akx-mq --save

Usage


file: akx-mq-config.js

var mqConfig = require( './config.json' );
var akxMq = require( 'akx-mq' )( mqConfig );
var logger = require( './logger' );

akxMq.addErrorHandling( function( err ){
    logger.log( 'mq', err );
} );

exports.akxMqMiddleware =  function(){
    var getMessage = function( req, res ){
        return res._body.wire.dataValues;
    };
    var callback = function( err, req, res, next ){
        if( error ){
            logger.log( 'mq', err, { req: req } )
        }
        return next();
    };
    return akxMq.publishMiddleware( { queue: 'wiresQ', getMessage: getMessage, callback: callback } );
};

exports.akxMqAddConsumer = akxMq.addConsumer;

Then in your routes file call the akx-mq-config.js file and create publisherMiddleware to publish messages to the queues, and add consumers to consume messages for they're respected queues.

file: routes.js

var akxMqConfig = require( './akx-mq-config' );

var users = require('../controllers/users');
server.post('/users', authMiddleware, users.create, akxMqConfig.akxMqMiddleware() );

akxMqConfig.akxMqAddConsumer( {
    queueNameHere: [ fn1, fn2, fn3, ... ],
    anotherQueueName: [ fn1, fn4, ... ]
} );

Note: The addConsumer function uses the keys as the queue names here so make sure that they are in the config file before adding them here. Also the array of functions as the value will be called in order synchronously (connect style middleware). Note that the publish and consumer share the same connection and channel, this is by design. The above example calls akxMqConfig.akxMqMiddleware() function returns back the middleware that will be used. Below are the api references and options.

API Reference


#publishMiddleware

instance.publishMiddleware({[queue, [getMessage, [callback]]]}) Returns a middleware function with the regular req, res, and next arguments.

Takes a POJO with three properties:

  • queue: String name of the queue you want to publish to.
  • getMessage: Function that are given the req, res objects to extract the message.
  • callback: Function that are given the req, res, and next arguments if an error occurs you can log.

example: instance.publishMiddleware({queue:'users', getMessage: getMessageFunc, callback: callbackFunc}) Note: All three are required.

#addConsumer

instance.addConsumer({[queue, [array of functions]]}) Adds consumers to the respected queue.

Takes a POJO. Uses the keys as the queue name and the values as the consumer.

  • queue {queueName:[ fn1, fn2, ...]}

example: instance.addConsume({queueName:[ fn1, fn2, ...]}) Note: that functions will be called in order with the arguments: queueName, parsedMsg, next. The next callback is similar to connect style but you can pass in next( true ) which will raise a flag that will ignore the rest of the functions and call the last function in the list. Else you can just call next() and it will call them in order one at a time. There is no limit to how many consumers you can add. Also the message wont be acknowledge until the last function has finished.

#addErrorHandling

instance.addErrorHandling([function]) Adds a catch all error handling function

Takes a function to be the general error handling function.

  • function: Just a regular function, named or anonymous.

example: instance.addErrorHandling(function(){ logger.log('message')}) Note: This is optional.

Options


| Property | DataType | Default | Description | |----------|----------|---------|-------------| | retry | Number | 60000 | How many milliseconds before retrying to connect to the server | | host | String | 'amqp://localhost' | The host for the server | |persistent| Boolean | false | If you want the message to persist if server goes down | | prefetch | Number | 0 | How many unAcked messages you want to allow before sending more down to the consumer | | noAck | Boolean | false | If you want no Acknowledge meant | | queues | Array | [ ] | An array of objects with 'name', and 'durable' properties |