Sending CouchDB Update Notifications to RabbitMQ.
Joe Williams - - June 06, 2009Working at Cloudant I use CouchDB on a daily basis. This evening for fun I decided to write some Ruby to take update notifications and push them into RabbitMQ. There are other examples of using the update notifications and Ruby in Couch such as the view updater out on the Couch wiki. It turned out super simple. There are a few AMQP libraries for Ruby, in this example I am going to use carrot. It’s based on the amqp library without all the eventmachine stuff. So here it goes:
#!/usr/bin/ruby
require ‘rubygems’
require ‘carrot’def main
queue = “couchdb”
run = true
couchq = Carrot.queue(:queue => queue)while run do
notifications = gets
if notifications == nil
run = false
else
couchq.publish(notifications)
endend
endmain
As you can tell we connect to a queue called “couchdb” on by default this is on localhost. Next we have a loop that continually runs and grabs updates from stdin. I then publish each notification to the queue and that’s that. To get the messages out of the queue I used irb and carrot.
[user@host ~]$ irb
irb(main):001:0> require ‘rubygems’
=> true
irb(main):002:0> require ‘carrot’
=> true
irb(main):003:0> couchq = Carrot.queue(:queue => “couchdb”)
=> #<Carrot::AMQP::Queue:0×7f8d2284b640 <snip>
irb(main):004:0> couchq.pop
=> “{\”type\”:\”updated\”,\”db\”:\”test1\”}\n”
So yeah, pretty simple stuff. Go ahead relax!
[EDIT 06/05/2009 2326 PST : Don’t forget to add the entry to your local.ini]
[update_notification]
couch_amqp=/PATH/TO/couch_amqp.rb
Categories: Blogs Joe Williams
Comments
thanks for this, it worked for me
Posted by gelinlik on 04 Sep 2009 at 20:42
Add comment
Erlang on Twitter
» fprogblogs (ФП-Блоги): dmzlj пишет: необъяснимое про erlang http://bit.ly/bWR1bK
» fprogblogs (ФП-Блоги): Dmitrii ‘Mamut’ Dimandt пишет: Flymake и Erlang http://bit.ly/cbaWMs
» sbtourist (Sergio Bossa): @dnene +1 for Clojure and/or Erlang :)
» delegatevoid (Timothy Parez): @TheColonial I’ll keep an eye on it… ever never seen anything about erlang before… only mentions from you
» pjimmy (Jimmy P): @TheColonial lol I thought you were just mad at your erlang install..
» TheColonial (OJ): @delegatevoid It’s me, trying to get a regular podcast up for erlang related stuff. Been on the backburner though.
» williamgouvea (William Gouvea): RT @dnene: My now publicly stated goal is to be competent at atleast 1 FP language (out of Scala / Clojure / Haskell / Erlang) by the year end
» williamgouvea (William Gouvea): RT @dnene: Preliminary learning for Scale, Clojure done, Haskell in progress, Erlang in queue
» k_s_zip (じっぷ): 暇なのでクジラ対策で脚光を浴びた?Scalaを勉強中なう。なるほどJava環境に並列化処理を施す1つの解になるわけだ。Rubyにもなんとなく似た雰囲気あるし、Erlangのような仕組みもある。これはこれで面白いw
» kyhpudding (Yuheng Kuang): 这个更好玩!RT @liancheng: @kyhpudding 嗯,还有一个例子是erlang的分布式数据库mnesia,原名是amnesia。然后经理疯了,说你们做一数据库,取个名字叫健忘症,这不行啊。于是Joe大叔一帮人等把第一个a给去掉了
Statistics
Number of aggregated posts: 10084
Number of comments: 564
Most recent article: September 07, 2010
Latest comments
» Simon cadbury on CouchDB Load Balancing and Replication using HAProxy.: Very nice Site number one topic Thanks you.. [url=“http://www.designscopia.com/products/outdoor-media/mobile-ads.asp”]mobile ads design [/url] | [url=“http://www.designscopia.com/products/print-material/stickers.asp”]stickers design [/url]
» dress on Reading Serialized PHP Objects from Erlang: canon lens mugs Nikon Mugs Canon Coffee Lens Mug Nikon Coffee Lens Mug anon coffee mug,canon lens mug,canon mug,canon coffee…
» dress on Fun with processes (Updated): canon lens mugs Nikon Mugs Canon Coffee Lens Mug Nikon Coffee Lens Mug anon coffee mug,canon lens mug,canon mug,canon coffee…