Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

have assertExchange return exchange info in promise callback? #49

Closed
mxriverlynn opened this issue Mar 12, 2014 · 3 comments
Closed

have assertExchange return exchange info in promise callback? #49

mxriverlynn opened this issue Mar 12, 2014 · 3 comments

Comments

@mxriverlynn
Copy link

I like the way assertQueue returns an object that has the queue name on it.

ch.assertQueue('whatever').then(function(q){
  q.queue; // the queue name: whatever
});

Can we get the assertExchange to do the same? Right now, it only seems to return an empty JS object. It would be very helpful for the code I'm writing to have the exchange name returned in the same way, so that I don't have to create a string var in so many places.

@squaremo
Copy link
Collaborator

I see what you mean -- you'd like to write

ch.assertExchange("literal name").then(function(ok) {
  doSomethingWithWhateverNameIsUsedAbove(ok.exchange);
});

The reason it works as it does it two-fold:

  1. The reply in the protocol (ExchangeDeclareOk) doesn't actually contain the exchange name (whereas QueueDeclareOk has 'queue' because it may be a name generated by the server); and 2. I didn't think about it a whole lot, and for most things I just return whatever the server sends.

But it is a good idea, I like it.

@squaremo
Copy link
Collaborator

Oh, ha, actually I say in the documentation that the server's reply contains the exchange name.

Opinions differ on this, apparently, even within the specification. In older versions of AMQP, you could supply an empty string as the name of an exchange to get the server to make one up for you, like you can with queues.

Long story short: the promise returned from #assertExchange now looks like {exchange: "foo"}.

@mxriverlynn
Copy link
Author

awesome! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants