watching CouchDB _changes?feed=continuous which returns chunked JSON

324 views
Skip to first unread message

Dobrica Pavlinusic

unread,
Nov 21, 2010, 3:37:27 PM11/21/10
to Mojolicious
I'm trying to implement queuing system on top of CouchDB using changes
feed described at:

http://wiki.apache.org/couchdb/HTTP_database_API#Changes

Problems are responses, which are chunked, with one JSON object in
each chunk. I don't really know how to get individual chunks using
Mojo::Client. I found _read sub which seems like a good place to
extract chunks, which I guess I could subclass and modify, but before
doing that I'm sure there is better way to solve this.

Thanks in advance for any hints about this.

Sebastian Riedel

unread,
Nov 21, 2010, 5:02:01 PM11/21/10
to mojol...@googlegroups.com
> Problems are responses, which are chunked, with one JSON object in
> each chunk. I don't really know how to get individual chunks using
> Mojo::Client. I found _read sub which seems like a good place to
> extract chunks, which I guess I could subclass and modify, but before
> doing that I'm sure there is better way to solve this.

Yes there is a better way built in.

https://github.com/kraih/mojo/blob/master/lib/Mojo/Client.pm#L1344

--
Sebastian Riedel
http://blog.kraih.com
http://mojolicious.org
http://twitter.com/kraih

Dobrica Pavlinušić

unread,
Nov 22, 2010, 9:54:36 AM11/22/10
to mojol...@googlegroups.com
Thanks a lot. Mojo is so full of useful stuff that it's sometimes hard
to find it :-)

For future reference, I needed also to split CouchDB output (because
it can return more than
one JSON in one chunk) and I ended up with following snippet:

https://github.com/dpavlin/angular-mojolicious/blob/master/couchdb-changes.pl

which might be useful when writing triggers based on changing CouchDB documents.

FWIW, chunked transfer is easier to use in Mojo::Client than in LWP::UserAgent
(which returns same documents over and over again when CouchDB sends
just newline).

> --
> You received this message because you are subscribed to the Google Groups "Mojolicious" group.
> To post to this group, send email to mojol...@googlegroups.com.
> To unsubscribe from this group, send email to mojolicious...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mojolicious?hl=en.
>
>

--
 ...2share!2flame... http://blog.rot13.org

Reply all
Reply to author
Forward
0 new messages