Karait消息队列系统
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.)评论
