incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Kocoloski <kocol...@apache.org>
Subject Re: best way to send a STOMP message on attachment upload?
Date Thu, 12 Nov 2009 16:03:41 GMT
On Nov 12, 2009, at 10:46 AM, Matteo Caprari wrote:

> Hi.
> 
> i need to notify an erlang process each time a couchdb database is updated.
> Reading the docs I learned how to use [update_notification] to fire a
> script that sends that message.
> 
> It's fine, but  my feeling is that sending a message from couchdb
> would be faster than starting a new 'heavy' process each time.
> 
> I'd like to hear some comments. Thanks!
> --
> :Matteo Caprari
> matteo.caprari@gmail.com

Hi Matteo, if you're willing to hack the source a bit this is easy to do.  CouchDB has a gen_event
system which generates the following set of events

{created, DbName}
{updated, DbName}
{deleted, DbName}

So, the easiest way to plug into this is to use that same update_notification system you've
been using, but instead of configuring an external script in the .ini system just pass an
Erlang function to it directly, e.g.:

couch_db_update_notifier:start_link(fun({created, DbName}) ->
        my_created_action();
    ({updated, DbName}) ->
        my_updated_action();
    ({deleted, DbName}) ->
        my_deleted_action()
    end).

You just need to figure out how to execute that bit of code during CouchDB's startup, e.g.
by calling it in couch_server_sup:start_server.  Best, Adam

P.S. Couch doesn't actually spawn the external script each time, right?  It should keep that
script running permanently and just send the new messages over stdio.


Mime
View raw message