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

errorhandler-nxg-cg

v1.1.8

Published

Library to connect to a message broker (like rabbitmq) and create a specific queue for error handling purposes.

Downloads

35

Readme

N|Solid

errorhandler-nxg-cg

[N|Solid

1. Introduction

This code has the objective to send messages to a message broker (like rabbitmq) queues for the N3xGen Platform (NXGP). This messages primarily will send an error message from NXGP components to be handled.

This library is useful to add into the NXGP components developed by their owners in order to have information for errors at flows execution time.

As components are used in the NXGP flows regardless that the library should be added on component code, when the flow is running, an exchange and some queues are created using the ID flow (assigned from NXGP). In the case of the queues, two queues are created for each step in the NXGP flow.

The queue naming structure is as follows:

flow�flowID:stepName:messages

flow�flowID:stepName:rebounds

Using the same structure for the NXGP error handler queue (for each step) the next queue is created, internally, by the errorhandler-nxg-cg library.

flow�flowID:stepName:deadletter

Where "flow" is a constant word, the "flowID" is the ID assigned by the NXGP to the flow, the "stepName" is the name configured to each node in the flow and the words "message"/"rebounds"/"deadletter" are constants.

And it is configured an exchange (the same used by the other queues).

Once this configuration is created by the library, messages can be sent to this queue.

2. Library Methods

The library can be installed from npm page with the next:

npm install errorhandler-nxg-cg, npm i errorhandler-nxg-cg or yarn install errorhandler-nxg-cg

_2.1. errorQueueListener

  • Args: No arguments are required.
  • Description: This method prepares the queue (deadletter) and the relation to the exchange, creating the queues and/or exchange if do not exist. Once the code is set, at run time each time it occurs an error, a message is sent to the configured queue.
  • Sample:
//Sample applied into a component function for NXGP

module.exports.process = async function processTrigger(msg, cfg, snapshot = {}) {
      try {
            await msgbkr.prepareErrorQueue();
            //Your code here...
      } catch (e) {
        console.error(`ERROR: ${e}`);
        this.emit('error', e);
    }
};

Resultant sample:

* Note: The library requires that the NXGP has the "ELASTICIO_LISTEN_MESSAGES_ON" environment variable. If this variable is not available, the library defines an auto-generated queue and exchange.

2.2. producerMessage

  • Args:
    • Message: A String that contains the message to be sent to the deadletter queue.
    • QueueName: The given name of the queue that will receive the messages to be handled.
  • Description: This method prepares the queue (deadletter) and the relation to the exchange, creating the queues and/or exchange if do not exist. Once the code is set, at the time the code line is executed, the message content is sent to the queue.
  • Sample:
//Sample applied into a component function for NXGP

module.exports.process = async function processTrigger(msg, cfg, snapshot = {}) {
      try {
            await msgbkr.producerMessage(msg,'myQueueName');
            //Your code here...
      } catch (e) {
        console.error(`ERROR: ${e}`);
        this.emit('error', e);
    }
};

Resultant sample:

* Note: The library requires that the NXGP has the "ELASTICIO_LISTEN_MESSAGES_ON" environment variable. If this variable is not available, the library defines an auto-generated queue and exchange (using the QueueName argument).

2.3. producerErrorMessage

  • Args:
    • Payload: The content of a request.
    • Error: The error message.
  • Description: This method prepares the queue (deadletter) and the relation to the exchange, creating the queues and/or exchange if do not exist. Once the code is set, at the time an error is catched and the code is executed a message is sent to the queue with the payload content and with the error message.
  • Sample:
//Sample applied into a component function for NXGP

module.exports.process = async function processTrigger(msg, cfg, snapshot = {}) {
      try {
            let {data} = msg;
            //Your code here...
      } catch (e) {
        console.error(`ERROR: ${e}`);
        this.emit('error', e);
        await msgbkr.producerErrorMessage(msg, e);
    }
};

Resultant sample:

* Note: The library requires that the NXGP has the "ELASTICIO_LISTEN_MESSAGES_ON" environment variable. If this variable is not available, the library defines an auto-generated queue and exchange.

3. Testing Code

The library contains a testing code that allows the user the behavior of the original code. This sample code shows to the user how to use the methods the library has.

The user must keep in mind that this code is developed to work without the NXGP, and according to this the code creates the default queues as explained at the end of each method explanation (at section 2).

To run the testing code the next command can be used (the starting location must be the code folder of this library):

npm test