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

Commit

Permalink
Added an ascoltatore option in mosca.Server.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Jul 25, 2013
1 parent 4743165 commit 7f085a2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var defaults = {
* - `port`, the port where to create the server.
* - `backend`, all the options for creating the Ascoltatore
* that will power this server.
* - `ascoltatore`, the ascoltatore to use (instead of `backend`).
* - `baseRetryTimeout`, the retry timeout for the exponential
* backoff algorithm (default is 1s).
* - `logger`, the options for Bunyan.
Expand Down Expand Up @@ -79,7 +80,7 @@ function Server(opts, callback) {
new Client(connection, that);
};

this.ascoltatore = ascoltatori.build(this.opts.backend);
this.ascoltatore = opts.ascoltatore || ascoltatori.build(this.opts.backend);
this.ascoltatore.on("error", this.emit.bind(this));

that.once("ready", callback);
Expand Down
58 changes: 58 additions & 0 deletions test/server_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,64 @@ describe("mosca.Server", function() {
}
]);
});

it("should support specifying an Ascoltatore instead of backend options in a tree-based topology", function(done) {
var d = donner(2, done);

async.waterfall([

function(cb) {
buildAndConnect(d, function(client1) {
cb(null, client1);
});
},

function(client1, cb) {
client1.on("publish", function(packet) {
expect(packet.payload).to.be.eql("some data");
client1.disconnect();
});

var subscriptions = [{
topic: "hello/#",
qos: 0
}
];

client1.subscribe({
subscriptions: subscriptions,
messageId: 42
});
client1.on("suback", function() {
cb(null);
});
},

function(cb) {
settings.ascoltatore = ascoltatori.build({
port: settings.port,
type: "mqtt",
json: false
});
settings.port = settings.port + 1000;
secondInstance = new mosca.Server(settings, cb);
},

function(cb) {
buildAndConnect(d, function(client2) {
cb(null, client2);
});
},

function(client2, cb) {
client2.publish({
topic: "hello/world",
payload: "some data"
});
client2.disconnect();
}
]);
});

it("should support unsubscribing a single client", function(done) {
var d = donner(2, done);
Expand Down

0 comments on commit 7f085a2

Please sign in to comment.