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

amq-broker

v0.0.4

Published

## Installation

Downloads

3

Readme

amq-broker

Installation

$ npm install amq-broker --save

Usage

Set up process variable CLOUDAMQP_URL or AMQP_URL pointing to the broker instance.

//module will lookup process variable and establish connection
const msgBroker = require("amq-broker");

//get the handle to Events construct
const Events = msgBroker.Events;

//Publish directly to an exchange named 'notify' with routing key 'create'

msgBroker.publish("notify", "createx", Events.simple({ name: "tx" }));

//Publish directly to a queue

msgBroker.sendToQueue(
  "transaction",
  Events.simple({ source: "shopify", id: "12345", amount: "45 SGD" })
);

//Consume directly from a queue
msgBroker.consume("transaction", (response) =>
  console.log("Recieved response : " + response)
);

//To release connections on exit, set up closeonExit with an optional handler
//Once the process terminate, connections will be released and the optional handler will be invoked

msgBroker.closeOnExit((err, success) => {
  if (err) {
    console.error("Error while releasing MQ connections", err);
    return;
  }
  console.log("Successfully released MQ connections");
});

Events

Events are data wrappers. Currently supports "simple" and "chained".

const msgBroker = require("sg-lab-broker");

//get the handle to Events construct
const Events = msgBroker.Events;

//create a simple event
let shopping = { source: "txn", id: "Tx1245", amount: "10 SGD" };

//wrap that in event using simple construct
let simpleEvent = Events.simple(shopping);

//create one more data
let sms = { to: "+3111", message: "Hello World!!" };

//lets create a chained event
let chainedEvent = Events.chained()
  .add("txn", shopping) //add shopping to the chain
  .add("sms", sms) //add sms also to the chain
  .build();

//Events construct helps to retrieve data within consumers
let smsData = Events.getData(chainedEvent, "sms");
//or
let shoppingData = Events.getData(simpleEvent);

Queue operations

//create a queue named 'queue-name'
msgBroker
  .createQueue("queue-name", {})
  .then((data) => console.log(data))
  .catch((error) => console.log(error));

//bind the queue, 'queue-name' to the exchange, 'exchange-name' using topic, '#.routing-key.#'
// #.routing-key.# means match any message which it's topic contains the string '.routing-key.'
msgBroker
  .bindQueue("queue-name", "exchange-name", '"#.routing-key.#')
  .then((data) => console.log(data))
  .catch((error) => console.log(error));

//unbind the queue, 'queue-name' for the topic, '#.routing-key.#' from the exchange, 'exchange-name'
msgBroker
  .unbindQueue("queue-name", "exchange-name", '"#.routing-key.#')
  .then((data) => console.log(data))
  .catch((error) => console.log(error));

//delete the queue named 'queue-name'
msgBroker
  .deleteQueue("queue-name", {})
  .then((data) => console.log(data))
  .catch((error) => console.log(error));