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

amqp_pattern

v1.1.0

Published

amqp class to easily manage different kind of patterns with almost no code

Downloads

5

Readme

amqp_pattern

amqp nodejs class to easily manage different kind of patterns with almost no code

logs are generated through tracer library(https://www.npmjs.com/package/tracer). Check tracer project to configurate your logs

Right now it has 4 possible patterns managed

  • fifo queue pattern (https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics)
  • publish/subscribe pattern (https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern)
  • rpc pattern (https://en.wikipedia.org/wiki/Remote_procedure_call)
  • rpc with strategy pattern (https://en.wikipedia.org/wiki/Strategy_pattern)

Unit tests require to have rabbitMQ installed on local.

historical of changes

  • 1.0.2
    • documentation nomenclature changes to follow npm standards
    • API documentation
  • 1.0.1 Corrected small unit tests issue
  • 1.0.0 Initial release

init / end connection connection

First is needed to instance the class. At oposite of main amqp class each instance will manage only one channel. It helps to avoid complexity and helps to control different logical elements in a simpler structured way.

'use strict';

const amqp_pattern = require('amqp_pattern');
const logger = require('tracer').colorConsole({level:'debug'});

var x = new amqp_pattern('amqp://localhost', logger);
x.init().then(async () => {
  x.dispose();
});

patterns

fifo queue pattern

A simple fifo pattern where the client send items to the queue with no need of any kind of feedback, except possible queuing failure (managed through basic exceptions). Consumer will process the work in the attached callback, requeuing any item who retrieves an exception.

queuing

var x = new amqp_pattern('amqp://localhost', logger);
x.init().then(async () => {
  await x.initQueue("test");
  for (var i = 0; i<100; i++)
    x.queue("test", i);
});

consume

var x = new amqp_pattern('amqp://localhost', logger);
x.init().then(async () => {
  x.consume("test", async (val) => {
    console.log(val);
  });
});

publish/subscribe pattern

A pattern where each message is related to more than one possible queue, filtered through basic mechanisms to decide whose queues with keep the messages.

  • The act of queuing is not called queuing anymore, it is called publish.
  • The way the message is redirected to each queue is called subscription.

Each one of these queues can have his own consumer, to process the message.

publish

var x = new amqp_pattern('amqp://localhost', logger);
x.init().then(async () => {
  await server.initExchange("queue_1", "fanout");
  for (var i = 0; i<100; i++)
    x.publish("test", i, "");
});

subscribe

var x = new amqp_pattern('amqp://localhost', logger);
x.init().then(async () => {
  await x.initQueue("queue_1");
  await x.initQueue("queue_2");
  await x.initExchange("queue_1", "fanout");
  await x.subscribe("queue_1", "queue", "");
  await x.subscribe("queue_2", "queue", "");
});

rpc pattern

An standard procedure flow through basic client/server interaction.

calls

var x = new amqp_pattern('amqp://localhost', logger);
x.init().then(async () => {
  console.log(await x.rpcCall("method", 1));
});

procedure

var x = new amqp_pattern('amqp://localhost', logger);
x.init().then(async () => {
  x.rpcServer("method", async (val) => {
    return val + 1;
  });
});

rpc with strategy pattern

Strategy pattern concept is to select the work to do in base an strategy chooser. Using amqr is a cool way to implement this pattern. If we at the same time want some rpc logic, then we can create some cool features.

Call itself does not differ from rpc pattern one, so no explanation needed, here

calls

var x = new amqp_pattern('amqp://localhost', logger);
x.init().then(async () => {
  console.log(await x.rpcCall("method", 1));
});

procedure

var x = new amqp_pattern('amqp://localhost', logger);
x.init().then(async () => {
  x.rpcStrategy("method",  async (a) => {
    if (a<50)
      return "a";
    return "b";
  }, {
    "a": async (a) => { return "a " + a;  },
    "b": async (a) => { return "b " + a; }
  });
});