How to unsubscribe all topics



There was a bug in our client app (did not perform unsubscribe) and looks like many subscriptions left on the Domain. How to remove all of them at once quickly just by domainName?
Since all client ids has virt***** postfix. (%clientid%_virt_xxx)



Hello Alex,

Removing all subscriptions using the API

Currently there is no general button to allow easy removal for all subscriptions. However, you can use the API to list your current subscriptions:

Then, for each subscription found, based on some criteria, you can remove then using:

Here is a fully working example that combines these two APIs to list your subscriptions and remove some of them. You can run this in the javascript console after complete login into the MyQttHub panel with an admin user: ({
   url : '/get-domain-subscriptions',
   data : {domainName : 'hub-xxxxx'},
   success : function (subscriptions) {
      for (var index in subscriptions) {
           var subscription = subscriptions[index];           
           if (subscription.topicFilter == "some-topic-filter") {
              console.log ("Removing subscription=" + subscription.topicFilter + ", qos=" + subscription.qos + ", clientId=" + subscription.clientId);
                  url : '/unsubscribe',
                  data : {domainName : 'hub-xxxx', clientId : subscription.clientId, subscriptions : [subscription.topicFilter]}

Note javascript API is the built-in function that launches API calls based on the protocol, parameters and urls described in the REST API documentation.

How to avoid having that subscriptions for _virt_ clientIds

There is a bug in the MyQttHub engine, that is already solved, and will be pushed to production soon, that causes subscriptions for devices with skipConnectionReplace enabled, to retain after that device disconnect withtout unsubscribing those topics.

Until fix is pushed to production, make sure your devices configured with skipConnectionReplace to unsubscribe everything before disconnecting.

In the meantime, you can save previous javascript block of code to make fast house keeping for subscriptions that shouldn’t be there.

Best Regards,