arempe93 / bunny-mock

A mock client for RabbitMQ modeled after the Bunny client in ruby
http://www.rubydoc.info/github/arempe93/bunny-mock
MIT License
44 stars 37 forks source link

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

Open hading opened 7 years ago

hading commented 7 years ago

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 commented 7 years ago

A possible solution (at least for my usage):

Another possibility:

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 commented 7 years ago

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 commented 7 years ago

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