使用bunny,如何在连接到现有队列时设置x-max-length

时间:2016-09-22 18:32:26

标签: rabbitmq bunny

我已经获得以下ruby函数来连接max_length值为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

调用时,会返回此错误:

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版本:2.0.1 Ruby版本:2.3.1

我已经尝试了ch.queue的各种参数,但无法找到设置最大队列长度值的方法。

建议欢迎。

1 个答案:

答案 0 :(得分:1)

看起来诀窍是将arguments哈希设置为ch.queue

的参数
    q = ch.queue(
        settings['queue'],
        durable: true,
        auto_delete: false,
        :arguments => { 'x-max-length' => settings['queue_length'].to_i }
    )
相关问题