Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

amqplib-retry

Package Overview
Dependencies
Maintainers
36
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

amqplib-retry - npm Package Compare versions

Comparing version 1.1.7 to 1.1.8-0-node-upgrade.0

8

lib/amqp_handler_wrapper.js

@@ -1,10 +0,10 @@

'use strict';var _=require('underscore');var Promise=require('bluebird');var config=require('./config');// attempts must be a number in milliseconds
"use strict";var _=require("underscore");var Promise=require("bluebird");var config=require("./config");// attempts must be a number in milliseconds
var getDefaultDelay=function getDefaultDelay(attempts){var delay=Math.pow(2,attempts);if(delay>60*60*24){// the delay for the message is longer than 24 hours. Fail the message and never retry again.
return-1}return delay*1000};module.exports=function(channel,clientQueueName,failureQueueName,clientHandler,delayFunction,initializer){var errorHandler=function errorHandler(msg){if(!initializer.isInitialized){// Delay in 1 MS to let the queues/exchange/bindings initialize
return Promise.delay(1).then(function(){return errorHandler(msg)})}_.defaults(msg,{properties:{}});_.defaults(msg.properties,{headers:{}});_.defaults(msg.properties.headers,{_retryCount:0});// _retryCount: 0 means this message has never been retried before.
msg.properties.headers._retryCount+=1;var expiration=(delayFunction||getDefaultDelay)(msg.properties.headers._retryCount);if(expiration<1){return channel.sendToQueue(failureQueueName,new Buffer(msg.content),msg.properties)}var properties={persistent:true,headers:{_originalProperties:msg.properties,// save the original properties.
msg.properties.headers._retryCount+=1;var expiration=(delayFunction||getDefaultDelay)(msg.properties.headers._retryCount);if(expiration<1){return channel.sendToQueue(failureQueueName,Buffer.from(msg.content),msg.properties)}var properties={persistent:true,headers:{_originalProperties:msg.properties,// save the original properties.
_targetQueue:clientQueueName// save the target queue name we should publish to after the delay is over.
}};_.extend(properties,{expiration:expiration.toString()});return channel.publish('',config.delayQueueName,new Buffer(msg.content),properties)};var handlerWrapper=function handlerWrapper(msg){return Promise.try(function(){return clientHandler(msg)}).catch(function(err){// Something went wrong. Let's handle this message.
}};_.extend(properties,{expiration:expiration.toString()});return channel.publish("",config.delayQueueName,Buffer.from(msg.content),properties)};var handlerWrapper=function handlerWrapper(msg){return Promise["try"](function(){return clientHandler(msg)})["catch"](function(err){// Something went wrong. Let's handle this message.
// Adding the string 'error' to support papertrail error filters.
console.error('Error: AMQP retry handler caught the following error: ',err);return Promise.try(function(){return errorHandler(msg)}).catch(function(err){// Something went wrong while trying to process the erroneous message.
console.error("Error: AMQP retry handler caught the following error: ",err);return Promise["try"](function(){return errorHandler(msg)})["catch"](function(err){// Something went wrong while trying to process the erroneous message.
// Sending nack so the client can try to process it again.

@@ -11,0 +11,0 @@ channel.nack(msg);throw err})}).then(function(){return(// We ack it for the user. Either way if the message has been processed successfully or

@@ -1,2 +0,2 @@

'use strict';var EXCHANGE_NAME='amqplib-retry';var DELAYED_QUEUE_NAME='amqplib-retry.delayed';var READY_QUEUE_NAME='amqplib-retry.ready';var READY_ROUTE_KEY='ready';module.exports={exchangeName:EXCHANGE_NAME,delayQueueName:DELAYED_QUEUE_NAME,readyQueueName:READY_QUEUE_NAME,readyRouteKey:READY_ROUTE_KEY};
"use strict";var EXCHANGE_NAME="amqplib-retry";var DELAYED_QUEUE_NAME="amqplib-retry.delayed";var READY_QUEUE_NAME="amqplib-retry.ready";var READY_ROUTE_KEY="ready";module.exports={exchangeName:EXCHANGE_NAME,delayQueueName:DELAYED_QUEUE_NAME,readyQueueName:READY_QUEUE_NAME,readyRouteKey:READY_ROUTE_KEY};
//# sourceMappingURL=config.js.map

@@ -1,4 +0,4 @@

'use strict';var Initializer=require('./initializer');var ReadyQueueConsumer=require('./ready_queue_consumer');var amqpHandlerWrapper=require('./amqp_handler_wrapper');module.exports=function(options){// validate options
if(!options.channel){throw new Error('\'channel\' not specified. See documentation.')}if(!options.consumerQueue){throw new Error('\'consumerQueue\' not specified. See documentation.')}if(!options.handler){throw new Error('\'handler\' not specified. See documentation.')}// set defaults
if(!options.failureQueue){options.failureQueue=options.consumerQueue+'.failure'}// initializing the objects
"use strict";var Initializer=require("./initializer");var ReadyQueueConsumer=require("./ready_queue_consumer");var amqpHandlerWrapper=require("./amqp_handler_wrapper");module.exports=function(options){// validate options
if(!options.channel){throw new Error("'channel' not specified. See documentation.")}if(!options.consumerQueue){throw new Error("'consumerQueue' not specified. See documentation.")}if(!options.handler){throw new Error("'handler' not specified. See documentation.")}// set defaults
if(!options.failureQueue){options.failureQueue=options.consumerQueue+".failure"}// initializing the objects
var initializer=new Initializer(options.channel,options.consumerQueue,options.failureQueue);var consumer=new ReadyQueueConsumer(options.channel);var wrapper=amqpHandlerWrapper(options.channel,options.consumerQueue,options.failureQueue,options.handler,options.delay,initializer);// initializing the queues, exchange and binding. Then starting the consumer

@@ -5,0 +5,0 @@ initializer.initialize().then(function(){return consumer.start()});// returning wrapper for given amqp handler function.

@@ -1,2 +0,2 @@

'use strict';var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if('value'in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError('Cannot call a class as a function')}}var config=require('./config');var Promise=require('bluebird');var Initializer=function(){function Initializer(channel,clientQueueName,failureQueueName){_classCallCheck(this,Initializer);this.channel=channel;this.clientQueueName=clientQueueName;this.failureQueueName=failureQueueName}_createClass(Initializer,[{key:'initialize',value:function initialize(){var self=this;return Promise.try(function(){return Promise.all([self.channel.assertQueue(config.delayQueueName,{durable:true,arguments:{'x-dead-letter-exchange':config.exchangeName,'x-dead-letter-routing-key':config.readyRouteKey}}),self.channel.assertQueue(config.readyQueueName,{durable:true}),self.channel.checkQueue(self.clientQueueName),self.channel.checkQueue(self.failureQueueName),self.channel.assertExchange(config.exchangeName,'direct',{durable:true})])}).then(function(){return self.channel.bindQueue(config.readyQueueName,config.exchangeName,config.readyRouteKey)}).then(function(){self.isInitialized=true})}}]);return Initializer}();module.exports=Initializer;
"use strict";function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj},_typeof(obj)}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,_toPropertyKey(descriptor.key),descriptor)}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor}function _toPropertyKey(arg){var key=_toPrimitive(arg,"string");return _typeof(key)==="symbol"?key:String(key)}function _toPrimitive(input,hint){if(_typeof(input)!=="object"||input===null)return input;var prim=input[Symbol.toPrimitive];if(prim!==undefined){var res=prim.call(input,hint||"default");if(_typeof(res)!=="object")return res;throw new TypeError("@@toPrimitive must return a primitive value.")}return(hint==="string"?String:Number)(input)}var config=require("./config");var Promise=require("bluebird");var Initializer=/*#__PURE__*/function(){function Initializer(channel,clientQueueName,failureQueueName){_classCallCheck(this,Initializer);this.channel=channel;this.clientQueueName=clientQueueName;this.failureQueueName=failureQueueName}_createClass(Initializer,[{key:"initialize",value:function initialize(){var self=this;return Promise["try"](function(){return Promise.all([self.channel.assertQueue(config.delayQueueName,{durable:true,arguments:{"x-dead-letter-exchange":config.exchangeName,"x-dead-letter-routing-key":config.readyRouteKey}}),self.channel.assertQueue(config.readyQueueName,{durable:true}),self.channel.checkQueue(self.clientQueueName),self.channel.checkQueue(self.failureQueueName),self.channel.assertExchange(config.exchangeName,"direct",{durable:true})])}).then(function(){return self.channel.bindQueue(config.readyQueueName,config.exchangeName,config.readyRouteKey)}).then(function(){self.isInitialized=true})}}]);return Initializer}();module.exports=Initializer;
//# sourceMappingURL=initializer.js.map

@@ -1,2 +0,2 @@

'use strict';var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if('value'in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError('Cannot call a class as a function')}}var config=require('./config');var Promise=require('bluebird');var ReadyQueueConsumer=function(){function ReadyQueueConsumer(channel){_classCallCheck(this,ReadyQueueConsumer);this.channel=channel}_createClass(ReadyQueueConsumer,[{key:'start',value:function start(){var self=this;return self.channel.consume(config.readyQueueName,function(msg){return Promise.try(function(){var targetQueueName=msg.properties.headers._targetQueue;var properties=msg.properties.headers._originalProperties;return self.channel.sendToQueue(targetQueueName,new Buffer(msg.content),properties)}).then(function(){return self.channel.ack(msg)}).catch(function(err){console.error('Error: while trying to process message from ready queue. err: '+err+', msg: '+JSON.stringify(msg));self.channel.nack(msg)})})}}]);return ReadyQueueConsumer}();module.exports=ReadyQueueConsumer;
"use strict";function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj},_typeof(obj)}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,_toPropertyKey(descriptor.key),descriptor)}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor}function _toPropertyKey(arg){var key=_toPrimitive(arg,"string");return _typeof(key)==="symbol"?key:String(key)}function _toPrimitive(input,hint){if(_typeof(input)!=="object"||input===null)return input;var prim=input[Symbol.toPrimitive];if(prim!==undefined){var res=prim.call(input,hint||"default");if(_typeof(res)!=="object")return res;throw new TypeError("@@toPrimitive must return a primitive value.")}return(hint==="string"?String:Number)(input)}var config=require("./config");var Promise=require("bluebird");var ReadyQueueConsumer=/*#__PURE__*/function(){function ReadyQueueConsumer(channel){_classCallCheck(this,ReadyQueueConsumer);this.channel=channel}_createClass(ReadyQueueConsumer,[{key:"start",value:function start(){var self=this;return self.channel.consume(config.readyQueueName,function(msg){return Promise["try"](function(){var targetQueueName=msg.properties.headers._targetQueue;var properties=msg.properties.headers._originalProperties;return self.channel.sendToQueue(targetQueueName,Buffer.from(msg.content),properties)}).then(function(){return self.channel.ack(msg)})["catch"](function(err){console.error("Error: while trying to process message from ready queue. err: "+err+", msg: "+JSON.stringify(msg));self.channel.nack(msg)})})}}]);return ReadyQueueConsumer}();module.exports=ReadyQueueConsumer;
//# sourceMappingURL=ready_queue_consumer.js.map
{
"name": "amqplib-retry",
"version": "1.1.7",
"version": "1.1.8-0-node-upgrade.0",
"description": "Retry failed attempts to consume a message, with increasing delays between each attempt.",

@@ -25,31 +25,27 @@ "author": "Lanetix <engineering@lanetix.com> (https://github.com/lanetix/)",

"compile": "babel src --out-dir lib --source-maps --minified",
"test-coveralls": "istanbul cover _mocha --report lcovonly -- -t 10000 -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
"cover": "istanbul cover _mocha -- -t 10000",
"lint": "eslint src test",
"prepublish": "npm run compile",
"test": "mocha -t 10000 && npm run lint"
"test": "c8 --clean true -r text -r lcov mocha --timeout 10000 --recursive --exit"
},
"dependencies": {
"amqplib": "^0.4",
"bluebird": "^3",
"underscore": "^1"
"amqplib": "^0.10.3",
"bluebird": "^3.7.2",
"underscore": "^1.13.6"
},
"devDependencies": {
"babel-cli": "^6",
"babel-preset-es2015": "^6",
"coveralls": "^2",
"eslint": "^3",
"eslint-config-standard": "^5",
"eslint-plugin-promise": "^2",
"eslint-plugin-standard": "^2",
"istanbul": "^0.4",
"mocha": "^3",
"should": "^10",
"sinon": "^1.12.2"
"@babel/cli": "^7.20.7",
"@babel/preset-env": "^7.20.2",
"eslint": "^8.31.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-promise": "^6.1.1",
"mocha": "^10.2.0",
"c8": "^7.12.0",
"should": "^13.2.3",
"sinon": "^15.0.1"
},
"babel": {
"presets": [
"es2015"
"@babel/preset-env"
]
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc