How to work with open streaming connection?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to work with open streaming connection?

jraedisch

I am trying to process a Twitter Streaming API response like this:

info("Just making sure, logging works...")
http(req <@ (consumer, token) >~ {_.getLines.foreach((line:String)=>info("New status: "+line))})

New statuses appear in the Dispatch DEBUG messages, but the info never appears.
Is that, because the io.Source is never finished and therefore the foreach is never executed?

Will I need to use an OutputStream via >>> or is there another best practice?

Thanks,
Jasper

Reply | Threaded
Open this post in threaded view
|

Re: How to work with open streaming connection?

n8han
Administrator
On 10/26/10 3:09 PM, jraedisch [via Databinder] wrote:

I am trying to process a Twitter Streaming API response like this:

info("Just making sure, logging works...") http(req <@ (consumer, token) >~ {_.getLines.foreach((line:String)=>info("New status: "+line))})

New statuses appear in the Dispatch DEBUG messages, but the info never appears.
Is that, because the io.Source is never finished and therefore the foreach is never executed?


Because of incompatibilities between Scala 2.7 and 2.8, the >~ method reads the InputStream into a string before passing it to Source.

Will I need to use an OutputStream via >>> or is there another best practice?


Use >> to process the InputStream. You can try passing that Source.fromInputStream directly; it might do the right thing (so that you can use getLines.foreach). If it doesn't, you can fall back to using the plain Java interfaces (BufferedReader, etc).

Nathan