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

Binding to a topic exchange does not support wildcards #16

Closed TimothyMDean closed 8 years ago

TimothyMDean commented 8 years ago

I have code that I'm trying to test that binds to a topic exchange as follows:

    channel = session.create_channel
    exchange = channel.topic('my-topic', :durable => true)
    queue = channel.queue('my-queue', :durable => true)
    queue.bind(exchange, :routing_key => "my-key.#")

The goal here is to handle any messages published to the topic exchange with a routing key of my-key.insert, my-key.update, or my-key.delete. This approach is consistent with the topic exchange routing example documented in the Bunny guides.

When I try to use bunny-mock to test this code, it does not honor the wildcard in my queue binding and as a result no messages are delivered. Looking at the source code, I see that wildcard replacement is performed on the routing key specified when publishing to a topic exchange (in the deliver method of exchanges/topic.rb). But there is no wildcard replacement performed on the routing key specified when binding to a topic exchange.

Is there a reason why wildcard replacement is only done for the routing key of the published message, rather than for the subscriber's binding? It seems like the more common use case for a pub/sub pattern to have the wildcards applied to the subscriber.

arempe93 commented 8 years ago

Hi @TimothyMDean - thanks for the feedback! I honestly did not know that was how the topic exchanges worked. There were only fanout exchanges in the app that I had written this for originally - and clearly did not read the docs on topic exchanges correctly.

If you could take a look at 2f87036 and let me know if that's the correct implementation that would be awesome. Thanks!

TimothyMDean commented 8 years ago

@arempe93 - Your commit looks like the correct implementation to me. I have pulled it into my test code and verified that it works as I would expect it to. Thanks for the quick turnaround on my issue.

arempe93 commented 8 years ago

No problem