Search code examples
rabbitmqbunny

Using bunny, how to set x-max-length when connecting to existing queue


I've got the following ruby function to connect to an existing rabbit queue with a max_length value of 10000

  def self.send(settings, event_str)
    conn = Bunny.new(
        hostname: settings['host'],
        username: settings['user'],
        password: settings['password'],
        virtual_host: settings['virtual_host']
    )
    conn.start
    ch = conn.create_channel
    q = ch.queue(
        settings['queue'],
        durable: true,
        auto_delete: false,
        x_max_length: 10000
    )
    ch.default_exchange.publish(event_str, :routing_key => q.name)
  end

When invoked, this error is returned:

PRECONDITION_FAILED - inequivalent arg 'x-max-length' for queue 'event_queue' in vhost '/sensu': received none but current is the value '100000' of type 'signedint'

Bunny version: 2.0.1 Ruby version: 2.3.1

I've experimented with various params toch.queue but can't find a way to set a value for max queue length.

Suggestions welcome.


Solution

  • Looks like the trick is to set an arguments hash as a param to ch.queue

        q = ch.queue(
            settings['queue'],
            durable: true,
            auto_delete: false,
            :arguments => { 'x-max-length' => settings['queue_length'].to_i }
        )