
Security News
NIST Under Federal Audit for NVD Processing Backlog and Delays
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Describe AMQP exchange and routing keys in a compact way (and as templates). Purpose is to allow compact (and external, e.g. via configuration strings) declaration of AMQP Exchange and routing keys, and to create routing key based on message data.
npm install amqp-route
Create a template with require("amqp-route").template(tplString)
. Then make a
routing key by using fill
method with data objects.
var route = require("amqp-route").template("MyExchange/route.key.{str}")
route.exchange; // "MyExchange"
route.fill({str: "foo"}); // "route.key.foo"
route.fill({}); // "route.key" (strips dots)
route.fill({skip: "here"}, {str: "hereIam"}) // fallback list of data objects
var route2 = require("amqp-route").template("route.key.{str}")
route2.exchange; // "" (Exchange is optional)
Generate a subset of available options for
node-amqp connection.exchange()
.
var route = require("amqp-route").template("MyExchange?dc-a/{routingKey}")
route.exchangeOpts; // {durable: true, confirm: true, autoDelete: false}
Options are a single letter (to set to true), prefixed by a -
(to set to
false).
Generate a subset of available options for
node-amqp exchange.publish()
.
var route = require("amqp-route").template("{routingKey}?mip")
route.pubOpts; // {mandatory: true, immediate: true, deliveryMode: 2}
Simlar to Exchange Options (single letter, optional -
). The exception is p
(for "persistent", which sets deliveryMode
.
Template object returned from require("amqp-route").template()
:
exchange
: exchange nameexchangeOpts
: parsed options suitable for
node-amqp connection.exchange()
template
: routing key template used in (template.fill())[#template-fill]pubOpts
: publishing options suitable for
node-amqp exchange.publish()
Creates a routing key for some data by replacing all strings in curly braces with value from the first object having that property. Any leading, trailing, or double work separators (dots) are removed.
var route = require("amqp-route").template("{a}.{b}.{c}.{d}")
var rk = route.fill({a: "A"}); // "A"
rk = route.fill({a: "A"}, {a: "X", c: "C"}); // "A.C"
rk = route.fill({a: "A", b: "B", d: "D, c: null}); // "A.B.D"
Publisher builds on Template, setting up an Exchange with options and always calling the callback, even when the Exchange is not in confirm mode. It also uses the publishing options from the Template.
var amqpRoute = require("amqp-route");
var amqpConn = require("amqp").createConnection(connectionOpts);
// create a publisher in confirm mode, durable and no autoDelete
amqpRoute.publisher(amqpConn, "My-Exchange?-acd/{routing}.{template}", function(err, pub){
var routingKeySources = [{routing: "sample"}, {template: "key"}];
var message = {important: "data"};
pub.publish(routingKeySources, message, function(err){
// message published with routing key "sample.key", confirm mode
// when NOT using confirm mode, this is called via process.nextTick()
});
});
Additionally, you can include further Exchange options.
var tpl = "My-Exchange?-acd/{routing}.{template}";
amqpRoute.publisher(amqpConn, tpl, {type: "direct"}, function(err, pub){
// now we are using a Direct exchange instead of topic
});
Publish a message, additional options are passed to
node-amqp exchange.publish()
and any
passed callback will be called regardless of confirm mode.
routeFillers
is an array of sources to create routing key from Template. It
corresponds to arguments passed in Template.fill()
.
FAQs
Data Routing Helpers for AMQP
The npm package amqp-route receives a total of 0 weekly downloads. As such, amqp-route popularity was classified as not popular.
We found that amqp-route demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.
Security News
TypeScript Native Previews offers a 10x faster Go-based compiler, now available on npm for public testing with early editor and language support.