question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Any plans for bus.unlisten?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mateodelnortecommented, May 12, 2014

Haha. No worries. 😉 I still need to update the README, but here’s an outline of the changes as I sent to a client:

Send/Listen:

You can unlisten or destroyListener directly from an instance of a bus:

If you create a listener:

  bus.listen('my.event', { ack: true }, function (event) {
    count++;
    event.handle.ack();
  });

You can tell it to stop listening via:

  bus.unlisten('my.event');

One thing to note is that, due to how RabbitMQ works, you may get a few more messages after you make the call to unlisten(). You know when it’s officially stopped when RabbitMQ responds. Unlisten gives back an EventEmitter which will tell you exactly when that is via a ‘success’ event:

  bus.unlisten('my.event').on('success', function () {
      bus.send('my.event', { test: 'data'}); // this event won't be

picked up by any local listeners by the same routing key });

If you want to physically destroy the queue this listener is attached on, you can use destroyListener():

  bus.destroyListener('my.event.4');

It also returns an EventEmitter to show success:

  bus.destroyListener('my.event').on('success', function () {
        // the queue will have been physically destroyed at this time
  });

Publish/Subscribe:

Since you may have multiple subscriptions on a routing key in a process (though probably not a great idea to do so), it doesn’t make sense to unsubscribe directly from the bus instance. So, when subscribing, a subscription object is returned to you:

  var subscription = bus.subscribe('my.event', { ack: true }, function

(event) { // do something for your event here });

And to unsubscribe, you exercise the unsubscribe() method on that subscription:

  subscription.unsubscribe();

On Mon, May 12, 2014 at 11:50 AM, Chris Abrams notifications@github.comwrote:

Cool! I clearly did not accept the challenge 😮

— Reply to this email directly or view it on GitHubhttps://github.com/mateodelnorte/servicebus/issues/16#issuecomment-42849801 .

0reactions
chrisabramscommented, May 12, 2014

Very nice! I like that you separated unlisten from destroyListener. This will be very helpful - I have a side project that I can now finish integration testing because of this 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

unlisten - Wiktionary
(computing) To cease to listen for incoming signals. Coordinate termsEdit · untalk. AnagramsEdit.
Read more >
Unlistened Definition & Meaning - Merriam-Webster
The meaning of UNLISTENED is not listened to : not heard.
Read more >
Documentation: 15: UNLISTEN - PostgreSQL
UNLISTEN is used to remove an existing registration for NOTIFY events. UNLISTEN cancels any existing registration of the current PostgreSQL session as a ......
Read more >
Unlistened definition and meaning | Collins English Dictionary
Unlistened definition: not heard or listened to | Meaning, pronunciation, translations and examples.
Read more >
Map.unlisten - Earth Engine - Google Developers
Map.unlisten ; idOrType, String, optional, Either an ID returned by listen() when a callback was registered, an event type, or nothing. If an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found