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

channel.default_exchange doesn't behave like default exchange #24

Open
hading opened this issue Nov 30, 2016 · 3 comments
Open

channel.default_exchange doesn't behave like default exchange #24

hading opened this issue Nov 30, 2016 · 3 comments

Comments

@hading
Copy link

hading commented Nov 30, 2016

The default exchange should (as I understand - please correct if I'm wrong) route a message to a queue specified by the routing_key even if it is not explicitly bound (ala https://www.rabbitmq.com/tutorials/amqp-concepts.html under "Default Exchange")

So something like:

channel.default_exchange.publish('message', routing_key: 'test_queue', persistent: true)

should always send the message 'message' to the queue 'test_queue', even with no explicit binding, assuming that that queue exists.

This doesn't seem to happen with BunnyMock.

@hading
Copy link
Author

hading commented Nov 30, 2016

A possible solution (at least for my usage):

  • make a subclass of direct exchange for the default exchange and return that from channel.default_exchange
  • override the publish method to look for the queue specified by the routing key before doing anything else - if found, bind it there. This would at least produce the illusion of all queues being automatically bound to the default exchange for publishing purposes.

Another possibility:

  • make a singleton subclass of direct exchange for the default exchange and return that from channel.default_exchange
  • on queue creation automatically bind to that exchange

If I get some time I'll see if I can work one of those up and see if it works for me and if so put in a pull request. If not, happy for any sort of solution.

@arnodirlam
Copy link

arnodirlam commented Sep 19, 2017

Sorry for reviving and old (but open) issue. Here's how I "solved" the issue:

# Override `BunnyMock::Queue#subscribe` to mimic the default exchange behavior
# of RabbitMQ. Also add the missing opposite `BunnyMock::Queue#cancel`.
module BunnyMock
  class Queue
    alias original_subscribe subscribe

    def subscribe(*args, &block)
      channel.default_exchange.add_route(name, self)

      original_subscribe(*args, &block)
    end

    def cancel
      channel.default_exchange.remove_route(name, self)
    end
  end
end

Can I open a PR to include this functionality in BunnyMock?

@arempe93
Copy link
Owner

of course @arnodirlam - make a PR and we can talk about migration

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

No branches or pull requests

3 participants