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

rabbit-listener

v1.0.3

Published

A message queue listener for RabbitMQ

Downloads

2

Readme

rabbit-listener

Listens for messages in RabbitMQ.

  • Fully compatible with rabbit-chatter
  • Easy to use and fast to implement
  • Stable
  • Very few dependencies
  • Build upon amqplib

Usage

Use npm to install the module:

	npm install rabbit-listener

Then use require() to load it in your code:

	var rabbitListener = require('rabbit-listener');

Initialize a new instance:

	var rabbit = rabbitListener.rabbit(options);

And then you can start listening for messages:

	rabbit.listen(function(msg){
		console.log('Message received: ' + msg.content.toString());		
	});

You will need to have RabbitMQ up and running for this to work.

Rabbit.listen takes a callback as parameter and that callback will retrieve the message object as parameter. I've printet the msg object from the tests and it looks like this:

{
    "fields": {
        "consumerTag": "amq.ctag-Y85cFepeqYK75qtz0iDrbg",
        "deliveryTag": 1,
        "redelivered": false,
        "exchange": "TEST",
        "routingKey": ""
    },
    "properties": {
        "headers": {},
        "correlationId": "CORRELATIONIDTEST",
        "timestamp": 1468420458017,
        "appId": "TESTAPPIDALL"
    },
    "content": {
        "type": "Buffer",
        "data": [
            84,
            69,
            83,
            84,
            73,
            78,
            71,
            32,
            49,
            50,
            51
        ]
    }
}

To read the content-property, just call .toString as in the example.

Options

You can of course provide options for setting up amqplib in rabbit-listener.

protocol

String

Default: 'amqp'

The protocol used to communicate with RabbitMQ (or perhaps another message queue?).

host

String

Default: 'localhost'

The URI of the server that hosts the RabbitMQ.

virtualHost

String

Default: ''

Used if RabbitMQ is configured with a virtual host.

port

Number

Default: 5672

The port that is open for connections to RabbitMQ.

username

String

Default: 'guest'

Use this if credentials is required.

password

String

Default: 'guest'

Use this if credentials is required.

exchangeType

String

Default: 'topic'

The topic for the exchange.

exchangeName

String

Default: 'rabbit-chat'

The name of the exchange.

routingKey

String

Default: ''

The name of the queue.

queueName

Deprecated. Use routingKey instead.

connectionTimeout

Number or null

Default: null

Set the number of miliseconds before the connections closes automatically. Send null in order to keep connection open.

prefetch

Number

Default: 0

Number of unacknowledged messages to fetch. Useful when you want to spread the load equally between servers.

callbackOnClose

Function

Default: An empty function

Specify a function that should be called when the connection is closed. Takes no parameters.

handleError

Function

Default: See below

Specify a function that should be called when an error occurs. The default looks like this:

function(ex) {
    console.log('ERROR in rabbit-listener: ' + JSON.stringify(ex, null, 4));
}

Tests

To run tests on this module, make sure that the modules for the tests are installed

	npm install rabbit-listener --dev

Then run:

	npm test

NOTICE: The test is not unit test but tests the functionality for submitting to RabbitMQ. So RabbitMQ is required to be installed locally in order to run the tests.

#Release notes

  • 1.0.2 - Renamed queueName to routingKey. queueName still works but is deprecated.
  • 1.0.1 - Added queueName option
  • 1.0.0 - First working version

#Futher reading

Further documentation the topics according to this module:

#Keywords

  • rabbitmq
  • listener
  • amqp
  • amqplib
  • message queue
  • service bus

License

The MIT License (MIT)

Copyright (c) 2016 Thorbjørn Gliese Jelgren (The Right Foot, www.therightfoot.dk)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.