Skip to content

Instantly share code, notes, and snippets.

@aricart
Last active March 1, 2017 17:53
Show Gist options
  • Save aricart/9e0a50543323465806217c8812dc6d22 to your computer and use it in GitHub Desktop.
Save aricart/9e0a50543323465806217c8812dc6d22 to your computer and use it in GitHub Desktop.
node-nats publisher permission snippet
# Generated
authorization {
ADMIN = {
publish = ">"
subscribe = ">"
}
PUB = {
publish = "foo"
}
SUB = {
subscribe= "foo"
}
users = [
{user: "admin", password: "test", permissions: $ADMIN},
{user: "pub", password: "test", permissions: $PUB},
{user: "sub", password: "test", permissions: $SUB},
]
# default of 5 seconds for an authorization timeout.
timeout: 5.0
}
'use strict';
var nats = require('nats').connect("nats://pub:test@localhost:4222");
nats.on('error', function(e) {
console.log("Error [" + e + "]");
console.log(e.stack);
process.exit();
});
function print(m) {
console.log("message: " + m);
}
// publish should fail
nats.publish("bar", "");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment