@pager/jackrabbit
Advanced tools
Comparing version 4.5.3 to 4.6.0
@@ -31,2 +31,6 @@ var amqp = require('amqplib/callback_api'); | ||
var DEFAULT_RPC_CLIENT_OPTIONS = { | ||
timeout: 3000 | ||
}; | ||
module.exports = exchange; | ||
@@ -57,3 +61,5 @@ | ||
connect: connect, | ||
publish: publish | ||
publish: publish, | ||
rpcClient: rpcClient, | ||
rpcServer: rpcServer | ||
}); | ||
@@ -63,2 +69,42 @@ | ||
function rpcClient (key, msg, options, replyTo) { | ||
if(!key) { | ||
throw new Error('missing rpc method'); | ||
} | ||
if(!replyTo && typeof options === 'function') { | ||
replyTo = options; | ||
} | ||
if (!options || typeof options !== 'object') { | ||
options = DEFAULT_RPC_CLIENT_OPTIONS; | ||
} | ||
var timeout = setTimeout(() => { | ||
replyTo(new Error('Timeout')); | ||
}, options.timeout || DEFAULT_RPC_CLIENT_OPTIONS.timeout); | ||
function onReply (reply) { | ||
clearTimeout(timeout); | ||
replyTo(reply); | ||
} | ||
function onNotFound (notFound) { | ||
clearTimeout(timeout); | ||
replyTo(new Error('Not Found')); | ||
} | ||
publish(msg, { | ||
key: key, | ||
mandatory: true, | ||
reply: onReply, | ||
notFound: onNotFound | ||
}); | ||
} | ||
function rpcServer (key, handler) { | ||
var rpcQueue = createQueue({ key: key, name: key, prefetch: 1, durable: false, autoDelete: true }); | ||
rpcQueue.consume(handler); | ||
} | ||
function connect(con) { | ||
@@ -131,2 +177,5 @@ connection = con; | ||
} | ||
if (opts.mandatory && opts.notFound) { | ||
channel.on('return', opts.notFound); | ||
} | ||
var drained = channel.publish(emitter.name, opts.key, new Buffer(msg), opts); | ||
@@ -133,0 +182,0 @@ if (drained) onDrain(); |
{ | ||
"name": "@pager/jackrabbit", | ||
"version": "4.5.3", | ||
"version": "4.6.0", | ||
"description": "Easy RabbitMQ for node", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14062
393
1