Library to connect to a message broker (like rabbitmq) and create a specific queue for error handling purposes.
npm install errorhandler-nxg-cg
flow�flowID:stepName:messages
flow�flowID:stepName:rebounds
flow�flowID:stepName:deadletter
npm install errorhandler-nxg-cg, npm i errorhandler-nxg-cg or yarn install errorhandler-nxg-cg
js
//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.
$3
- 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:
`js
//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).
$3
- 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:
`js
//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`