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

Commit

Permalink
Merge pull request #451 from adpdigital/publishSubscriptions
Browse files Browse the repository at this point in the history
Introduce publishSubscriptions option, so that subscription $SYS topic can be switched off
  • Loading branch information
mcollina committed Apr 18, 2016
2 parents c76b680 + 6a5cfa5 commit 37497cf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
8 changes: 6 additions & 2 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ function modernize(legacy) {
"maxInflightMessages",
"stats",
"publishNewClient",
"publishClientDisconnect"
"publishClientDisconnect",
"publishSubscriptions"
];

// copy all conserved options
Expand Down Expand Up @@ -250,7 +251,8 @@ function validate(opts, validationOptions) {
'maxInflightMessages': { type: 'integer' },
'stats': { type: 'boolean' },
'publishNewClient': { type: 'boolean' },
'publishClientDisconnect': { type: 'boolean' }
'publishClientDisconnect': { type: 'boolean' },
'publishSubscriptions': { type: 'boolean' }
}
});

Expand Down Expand Up @@ -333,6 +335,7 @@ function defaultsLegacy() {
stats: false,
publishNewClient: true,
publishClientDisconnect: true,
publishSubscriptions: true,
maxInflightMessages: 1024,
logger: {
name: "mosca",
Expand Down Expand Up @@ -368,6 +371,7 @@ function defaultsModern() {
stats: false,
publishNewClient: true,
publishClientDisconnect: true,
publishSubscriptions: true,
maxInflightMessages: 1024,
logger: {
name: "mosca",
Expand Down
35 changes: 19 additions & 16 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var nop = function() {};
* - `stats`, publish the stats every 10s (default false).
* - `publishNewClient`, publish message to topic "$SYS/{broker-id}/new/clients" when new client connects.
* - `publishClientDisconnect`, publish message to topic "$SYS/{broker-id}/disconnect/clients" when a client disconnects.
* - `publishSubscriptions`, publish message to topic "$SYS/{broker-id}/new/(un)subscribes" when a client subscribes/unsubscribes.
*
* Interface may contain following properties:
* - `type`, name of a build-in type or a custom type factory
Expand Down Expand Up @@ -261,25 +262,27 @@ function Server(opts, callback) {
);
});

that.on("subscribed", function(topic, client) {
that.publish({
topic: "$SYS/" + that.id + "/new/subscribes",
payload: JSON.stringify({
clientId: client.id,
topic: topic
})
if(that.modernOpts.publishSubscriptions) {
that.on("subscribed", function(topic, client) {
that.publish({
topic: "$SYS/" + that.id + "/new/subscribes",
payload: JSON.stringify({
clientId: client.id,
topic: topic
})
});
});
});

that.on("unsubscribed", function(topic, client) {
that.publish({
topic: "$SYS/" + that.id + "/new/unsubscribes",
payload: JSON.stringify({
clientId: client.id,
topic: topic
})
that.on("unsubscribed", function(topic, client) {
that.publish({
topic: "$SYS/" + that.id + "/new/unsubscribes",
payload: JSON.stringify({
clientId: client.id,
topic: topic
})
});
});
});
}

that.on("clientDisconnected", function(client) {
if(that.modernOpts.publishClientDisconnect) {
Expand Down

0 comments on commit 37497cf

Please sign in to comment.