jmesnil / stomp-websocket

Stomp client for Web browsers and node.js apps
http://jmesnil.net/stomp-websocket/doc/
Apache License 2.0
1.44k stars 586 forks source link

Support for Deleting a Durable Subscription #114

Open Forusim opened 9 years ago

Forusim commented 9 years ago

In the latest 2.3.4 it is not possible to delete a durable subscription. In the documentation for RabbitMQ or ActiveMQ it is said: "To permanently delete a durable subscription, send an UNSUBSCRIBE frame for the subscription ID with the persistent header set to true."

The easiest way to this, would be to provide the subscription headers to the client.unsubscribe():

Client.prototype.subscribe = function(destination, callback, headers) {

...some code....

  return {
    id: headers.id,
    unsubscribe: function() {
      return client.unsubscribe(headers);
    }
  };
};

The client.unsubscribe() should be changed to this:

Client.prototype.unsubscribe = function(headers) {
  delete this.subscriptions[headers.id];
  return this._transmit("UNSUBSCRIBE", headers);
};
fridgebuzz commented 8 years ago

My JavaScript is extremely rusty, but should this not be:

  return {
    id: headers.id,
    unsubscribe: function(headers) {
      return client.unsubscribe(id, headers);
    }
  };

with client.unsubscribe() changed to:

Client.prototype.unsubscribe = function(id, headers) {
  delete this.subscriptions[id];
  if (headers == null) {
    headers = {};
  }
  headers.id = id;
  return this._transmit("UNSUBSCRIBE", headers);
};

so that subscription.unsubscribe() can be called with an optional 'headers' argument? If I'm wrong, corrections are very welcome!

fridgebuzz commented 8 years ago

Actually, I found an error myself. Let's try this again. I've tried this and it works, which doesn't mean that the OP's code does not also work.

return {
    id: headers.id,
    unsubscribe: function(hdrs) {
      return client.unsubscribe(headers.id, hdrs);
    }
  };