消息队列系统 Karait
openkk
13年前
<p>Karait是一个消息<span class="wp_keywordlink_affiliate">队列</span>系统,其消息存储采用了<span class="wp_keywordlink_affiliate">MongoDB</span>的Capped Collections结构,这一结构的特点就是集合的大小可设定,当数据大小超出设定大小时,新数据会抹掉旧数据。</p> <p><span class="wp_keywordlink_affiliate">Karait</span>目前提供Python和Ruby的客户端操作包,也就是说你可以使用Python或Ruby来写消息,用Python或Ruby来读队列。</p> <p>Ruby 版本示例代码:</p> <pre class="brush:ruby; toolbar: true; auto-links: false;">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.)</pre> <p></p> <p><strong>项目主页:</strong><a href="http://www.open-open.com/lib/view/home/1322744792155" target="_blank">http://www.open-open.com/lib/view/home/1322744792155</a></p>