3

I am attempting to use Scala dispatch but been both a Scala neewbie and the face that Dispatch api is symbol crazy Im confused on how I can stream a large http response and process it line by line. Any help would be appreciated.

Cheers, Chris.

Note:

This isn't working for me:

Http(url(Config.publisherUrl) > as.stream.Lines(line => println(line)))

The lines are never printed.

Edit:

The lines were being printed, but only when there was more than one line in the response. The issue seems to be that I can stream the data line by line, but the very last line is omitted.

scravy
  • 11,904
  • 14
  • 72
  • 127
Owen
  • 6,992
  • 7
  • 44
  • 77
  • Are you seeing an error of some kind? Did you import `dispatch._`? Do you have an execution context in scope? It's hard to help without a little more information, but this looks like it should be working. – Travis Brown Jul 12 '13 at 02:08
  • 3
    Also note that there's exactly one non-standard library / language symbol in this code, and it's reasonably intelligible (to my eye, at least). The "Dispatch is symbol-crazy" meme is a little tiresome. – Travis Brown Jul 12 '13 at 02:12
  • @TravisBrown thanks for your personal opinion, tiresome it may be, but non the less apt. No errors, and yes dispatch._ is in scope, what I am not seeing is the lines been printed. – Owen Jul 12 '13 at 05:03

1 Answers1

0

I had the same problem. What you could do. I read it as input stream, then converted it to Akka stream and returned source.

import akka.stream.scaladsl.{Source, StreamConverters}
  val futureStream = Http(url(urlString) > as.Response(_.getResponseBodyAsStream))
        futureStream.map { inputStream =>
          val source = () => inputStream
          StreamConverters.fromInputStream(source)
        }

It worked for me.

Mahesh Chand
  • 3,158
  • 19
  • 37