Skip to content
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.

Commit

Permalink
Better handling of the id of the broker in the $SYS namespace.
Browse files Browse the repository at this point in the history
References #95.
  • Loading branch information
mcollina committed Feb 18, 2014
1 parent 8f2ad75 commit 6460c5a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ $ mosca --help
--https-bundle serve a MQTT.js-based client at /mqtt.js on HTTPS
--only-http start only an mqtt-over-websocket server
--disable-stats disable the publishing of stats under /$SYS
--broker-id <id> the id of the broker in the $SYS/<id> namespace
-c, --config <c> the config file to use (override every other option)
-d, --db <path> the path were to store the database
-v, --verbose set the bunyan log to INFO
Expand All @@ -127,6 +128,8 @@ var mosca = require('mosca');

module.exports = {
port: 4883,
id: 'mymosca', // used to publish in the $SYS/<id> topicspace
stats: true, // publish stats in the $SYS/<id> topicspace
logger: {
level: 'info'
},
Expand Down
5 changes: 4 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ function start(program, callback) {
opts.backend.prefix = program.parentPrefix;

if (program.disableStats) {
defopts.stats = false;
opts.stats = false;
}

opts.id = program.brokerId;

if (program.cert || program.key) {
if (program.cert && program.key) {
opts.secure = {};
Expand Down Expand Up @@ -240,6 +242,7 @@ module.exports = function cli(argv, callback) {
.option("--https-bundle", "serve a MQTT.js-based client at /mqtt.js on HTTPS")
.option("--only-http", "start only an mqtt-over-websocket server")
.option("--disable-stats", "disable the publishing of stats under /$SYS", null, true)
.option("--broker-id <id>", "the id of the broker in the $SYS/<id> namespace")
.option("-c, --config <c>", "the config file to use (override every other option)")
.option("-d, --db <path>", "the path were to store the database")
.option("-v, --verbose", "set the bunyan log to INFO")
Expand Down
4 changes: 2 additions & 2 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ function Server(opts, callback) {
new Client(connection, that);
};

// each Server has a uuid for logging purposes
this.id = uuid();
// each Server has a dummy id for logging purposes
this.id = this.opts.id || uuid().split("-")[0];

this.ascoltatore = opts.ascoltatore || ascoltatori.build(this.opts.backend);
this.ascoltatore.on("error", this.emit.bind(this));
Expand Down
11 changes: 9 additions & 2 deletions test/abstract_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1630,10 +1630,17 @@ module.exports = function(moscaSettings, createConnection) {
});
});

it("should have an id which is an uuid", function() {
it("should have an id which is a truncated uuid by default", function() {
// validate an uuid with a mirror test
var id = uuid.unparse(uuid.parse(instance.id));
expect(id).to.eql(instance.id);
expect(id).to.eql(instance.id + "-0000-0000-0000-000000000000");
});

it("should have a configurable id", function(done) {
var newSettings = moscaSettings();
newSettings.id = "4242";
secondInstance = new mosca.Server(newSettings, done);
expect(secondInstance.id).to.eql("4242");
});

describe("stats", function() {
Expand Down
8 changes: 8 additions & 0 deletions test/cli_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,4 +561,12 @@ describe("mosca.cli", function() {
expect(server.opts.stats).to.equal(false);
});
});

it("should allow to specify a broker id", function(done) {
args.push("--broker-id");
args.push("44cats");
var s = startServer(done, function(server) {
expect(server.id).to.equal("44cats");
});
});
});
2 changes: 1 addition & 1 deletion test/stats_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var EventEmitter = require("events").EventEmitter;

describe.only("mosca.Stats", function() {
describe("mosca.Stats", function() {
var instance;
var server;
var clock;
Expand Down

0 comments on commit 6460c5a

Please sign in to comment.