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

@lasmala/amqp-connection-manager

v1.1.4

Published

[![Build Status](https://travis-ci.com/lerollq/amqp-connection-manager.svg?branch=master)](https://travis-ci.com/lerollq/amqp-connection-manager) ![Coveralls github](https://img.shields.io/coveralls/github/lerollq/amqp-connection-manager)

Downloads

3

Readme

Amqp-Connection-Manager

Build Status Coveralls github

npm install @lasmala/amqp-connection-manager

A small client library built on top of amqplib

Features

  • Attempting to reconnect automatically after connection is closed or disconnected

  • Possibility to configure: - Maximum number of attempts - Delay between each attempt

  • Possibility to provide a fallback function, called once the limit of attempts is reached Can be useful to trigger a notification on your side

Basic Example

import AmqpConnectionManager from '@lasmala/amqp-connection-manager'

// By default attempt connection on `amqp://localhost` as hostname and `5672` as port
const connection = new AmqpConnectionManager()

const channel = connection.createChannel({
  setup: (channel: amqplib.Channel) => {
    return channel.assertQueue('queue', { autoDelete: true, durable: false })
  },
})

Advanced Example

import AmqpConnectionManager from "@lasmala/amqp-connection-manager"

const connection = new AmqpConnectionManager({
    // url can either be a string or an object
    url: {
        hostname: "localhost",
        port: 5671,
        protocol: "amqp",
        password: "your-password",
        username: "your-username"
    },
    reconnectionOptions: {
        delay: 1000 // Default value 5000,
        maximumAttempts: 100 // Default -1, meaning unlimited attempt
        fallback: () => {
            // This method will be triggered once the 100 maximumAttempts is reached
        }
    }
})
const channel = connection.createChannel({
    setup: (channel:amqplib.Channel) => Promise.all([
            channel.assertExchange('exchange', 'fanout', { durable: false, autoDelete: true }),
            channel.assertQueue('', { autoDelete: true, durable: false }).then(({ queue }) => {
                return channel.bindQueue(queue, 'exchange', '').then(() =>
                    channel.consume(queue, (msg) => console.log("Incomming message", msg?.content.toString())))
        }),
    ])
})

channel.publish('exchange', '', Buffer.from('Send new message'))

Publish Message To Exchange / Send Message To Queue

Trying to publish/send a message while the channel is not yet created, or the connection closed/pending will result in a lose of the message

....
    channel.publish("exchange", "routing-key", Buffer.from("message content"))
    .then(() => {
        // Message published
    })
    .catch((err)=>{
        // Handle error
    })

    channel.sendToQueue('queue_name', Buffer.from("message content"))
    .then(() => {
        // Message sent to the queue
    })
    .catch((err)=>{
        // Handle error
    })
....

Events

  • Connection Events
....
    connection.on('connect', () => {
      // Emitted once the connection is established
    })
    connection.on('reconnect', (attempt:number) => {
      // Emitted during a connection attempt
    })
    connection.on('error', (err:any) => {...})
    connection.on('close', (err?:any) => {...})
....
  • Channel Events
....
    channel.on('error', (err:any) => {...})
    channel.on('create', (err?:any) => {
        // Emitted as soon the channel has been successfully created
    })
....

Inspired by: node-amqp-connection-manager