jondot / sneakers

A fast background processing framework for Ruby and RabbitMQ
https://github.com/jondot/sneakers
MIT License
2.25k stars 332 forks source link

Use sneakers with default exchange #105

Closed abezzub closed 9 years ago

abezzub commented 9 years ago

Is Sneakers supposed to work with default exchange? If I setup Sneakers like this:

Sneakers.configure(amqp: ENV["CLOUDAMQP_URL"],
                   vhost: ENV["CLOUDAMQP_VHOST"],
# other settings...
                   exchange: "")

I get this error (partial stack trace):

Unexpected error ACCESS_REFUSED - operation not permitted on the default exchange
  /.rvm/gems/ruby-2.2.1/gems/bunny-1.7.0/lib/bunny/channel.rb:1915:in `raise_if_continuation_resulted_in_a_channel_error!'
/.rvm/gems/ruby-2.2.1/gems/bunny-1.7.0/lib/bunny/channel.rb:1073:in `queue_bind'
/.rvm/gems/ruby-2.2.1/gems/bunny-1.7.0/lib/bunny/queue.rb:103:in `bind'
/.rvm/gems/ruby-2.2.1/gems/sneakers-1.0.2/lib/sneakers/queue.rb:39:in `block in subscribe'
/.rvm/gems/ruby-2.2.1/gems/sneakers-1.0.2/lib/sneakers/queue.rb:38:in `each'
/.rvm/gems/ruby-2.2.1/gems/sneakers-1.0.2/lib/sneakers/queue.rb:38:in `subscribe'
/.rvm/gems/ruby-2.2.1/gems/sneakers-1.0.2/lib/sneakers/worker.rb:102:in `run'

Error happens here (in queue.rb):

    routing_keys.each do |key|
      queue.bind(@exchange, :routing_key => key) # error!
    end

If I understand correctly all queues are binded to default exchange by default, so bind can be skipped if @exchange is a default exchange. If it is OK to support default exchange I will be happy to submit a PR. I assume something like this should do the trick:

    if @opts[:exchange].length > 0
      routing_keys.each do |key|
        queue.bind(@exchange, :routing_key => key)
      end
    end

I tested above with my app and it works. Let me know what you think.

michaelklishin commented 9 years ago

Default exchange has implicit bindings and is not supposed to be bound explicitly. Sneakers does not take this into account.

sheerun commented 9 years ago

A workaround is to set :routing_key => [] in Sneakers.configure

sheerun commented 9 years ago

@abezzub Why did you close?

sheerun commented 9 years ago

Oh. I see the commits now.