2016-09-22 50 views
0

我已經得到了下面的Ruby功能與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 

一個max_length值連接到現有的兔子隊列調用時當如何設置X-最大長度,返回此錯誤:

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' 

兔子版本:2.0.1 紅寶石版本:2.3.1

我已經嘗試了各種PARAMS到ch.queue但無法找到設置最大隊列長度值的方法。

建議歡迎。

回答

1

貌似訣竅是設置arguments散列作爲一個參數去ch.queue

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