消息隊列系統 Karait

openkk 14年前發布 | 22K 次閱讀 MongoDB Python Ruby NoSQL數據庫

Karait是一個消息隊列系統,其消息存儲采用了MongoDB的Capped Collections結構,這一結構的特點就是集合的大小可設定,當數據大小超出設定大小時,新數據會抹掉舊數據。

Karait目前提供Python和Ruby的客戶端操作包,也就是說你可以使用Python或Ruby來寫消息,用Python或Ruby來讀隊列。

Ruby 版本示例代碼:

require 'karait'

queue = Karait::Queue.new(
    :host => 'localhost', # MongoDB host. Defaults to localhost.
    :port => 27017, # MongoDB port. Defaults to 27017.
    :database => 'karait', # Database that will store the karait queue. Defaults to karait.
    :queue => 'messages', # The capped collection that karait writes to. Defaults to messages.
    :average_message_size => 8192, # How big do you expect the messages will be in bytes? Defaults to 8192.
    :queue_size => 4096 # How many messages should be allowed in the queue. Defaults to 4096.
)

queue.write({
    :name => 'Benjamin',
    :action => 'Rock'
})

# or

message = Karait::Message.new
message.name = 'Benjamin'
message.action = 'Rock!'

queue.write(message, :routing_key => 'my_routing_key', :expire => 3.)

項目主頁:http://www.baiduhome.net/lib/view/home/1322744792155

 本文由用戶 openkk 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!