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

feathers-amqp-client

v0.0.10

Published

A simple AMQP client for feathers.js applications

Downloads

3

Readme

Feathers AMQP Client

Introduction

This library allows a feathers.js app to receive messages from an AMQP 0.8 broker (e.g. RabbitMQ). A service function can be associated with a queue, so that messages pushed on the queue will be passed to this feathers service.

Its main use case is a 'job-queue' model, where one or many event producers publish events, and multiple consumers consume these events, but each event must go to only one consumer.

This is different to feathers sync, which sends all events to all clients, so that they can synchronise their internal state.

How to use

receiver.service.js

const { bindStream } = require('feathers-amqp-client');
const createService = require('feathers-memory');

module.exports = function (app) {
    app.use('/posts', createService({}));
    const service = app.service('posts');

    bindStream(service.create.bind(service), {
      server: {name: 'amqp://user:pass@host:port'},
      exchange: { name: 'my-exchange'},
      queue: { name: 'my-task-queue' }
    });
}

The above example creates a simple in-memory resource, 'posts', and connects it to the task queue, 'my-task-queue'. The task queue will be configured to draw messages from the 'my-exchange' exchange. Neither the queue, nor the exchange, need exist beforehand.

service.create.bind(service) is necessary, as feathers services require access to the this context.

Message Format and Manipulation

feathers-amqp-client expects messages in the following form:

{ data: {...}}

In other words, an object with a data property. This data property will be passed directly into bound service function. To manipulate the data before passing it to the service, you can do something like this:

bindStream(data => {
    const dataForService = /* do something to the data */
    return service.create(dataForService)
}), {
    exchange: { name: 'my-exchange'},
    queue: { name: 'my-task-queue' }
});

Handling failure

feathers-amqp-client automatically reconnects on unexpected errors or server-triggered disconnects. This means it can recover after the AMQP broker crashes. However,any messages sent between the broker restart and the re-established connection will be lost, unless the queue is set up to persist them.

The client will wait 5 seconds after a disconnect before reconnecting. To change this, set reconnectDelay in the config parameter to bindStream.

Development and Testing

To run the tests locally:

npm install
npm test

Note - for the integration tests you must have docker installed. The tests assume the docker socket is available at /var/run/docker.sock

To override this (e.g. on Windows) set the DOCKER_SOCKET_PATH environment variable.