Questions on Activator Template: Akka Sample Twitter Streaming

18 views
Skip to first unread message

Dagny T

unread,
Jul 16, 2016, 1:55:55 AM7/16/16
to Akka User List
Hi there! Akka newbie. Trying to learn the latest Akka Http Streams API from this:http://www.lightbend.com/activator/template/akka-sample-twitter-streaming ; I'm running into bizarre behavior with that; and posted my list of questions and what I've tried in the Disqus comments just under that Template. Hoping someone with reliable current experience with the Akka Http Streams API could please help with suggestions for where to find answers to my questions, please. THANKS!

Akka Team

unread,
Jul 22, 2016, 6:00:30 AM7/22/16
to Akka User List
Hi,

There are lot of questions there, but I try to answer a few.

(disclaimer, this is not our template so I have not checked the code in detail)

> - I don't see any Actors, Flows, Materializers, Sources, Sinks being used explicitly in this code; so OK to assume this gets handled by implicit vals within Akka Http Stream?

It does not use streaming everywhere, but only on the entity bytes: https://github.com/vrcod/akka-sample-twitter-streaming/blob/master/src/main/scala/TwitterStreamer.scala#L79

Materializers are used, see here (and note that it is implicit, so it is not passed explicitly as a parameter): https://github.com/vrcod/akka-sample-twitter-streaming/blob/master/src/main/scala/TwitterStreamer.scala#L32

> i.e. I don't see any loops; but clearly people tweet about London or Clinton 24/7; and my debugger breakpoint jumps back to checking the response code, then disappears!

This is multithreaded code where the chain is not necessarily executing on the same thread. See my blog post here for details on this: http://blog.akka.io/streams/2016/07/06/threading-and-concurrency-in-akka-streams-explained

Ordinary step debugging simply does not work for asynchronous systems as control crosses thread boundaries which the debugger is not aware of.

> I do see how Tweets are parsed from JSON; but then how does the underlying Akka implementation know the clean Byte boundary to pull data into?

I don't understand this question. Can you elaborate?

> How would this client typically force a CLOSE for the socket connection?


> Or, is the assumption that implicit Actors run as daemons monitoring stream Source input?

I am not sure what do you mean by Actors running as daemons. There are actors yes, they run the stream. And there is a parent actor which is owned by the Materializer. If that actor stops (due to system shutdown or its parent stops) then all the stream code materialized by that materializer also stop. You can also explicitly shutdown a Materializer. KillSwitch is recommended though.

> Does Akka Http Stream open some kind of Async Http socket connection with push notifications; and where can I read a clear and reliable explanation of the essentials for how that works from the NIO layer, through to TCP, through Reactive Stream, Akka Stream, then Akka Http layers?

I cannot answer this as this seems to be Twitter specific and I don't know the details there. From the code it seems like that it just returns a long HTTP response, i.e. the connection is kept open and new data arrives over time. This is the code that gets the HTTP response body as a stream: response.entity.dataBytes

> Is the exception handling in this example rigorous; i.e. my Debugger stops hitting breakpoints, while the process is still running. Where else needs a Try block?

I am not sure, it is not our code and I am too lazy to review it :)

> Why does the response.status != 200 return a Future; but the other block of code, not have to create a Future to return? Certainly streamed data is async; and needs some kind of Future created -- is this somehow embedded in the Akka Http Stream API?

the request.flatMap { response => } block ensures that you already have the response headers. It is async (flatMap on a Future), and the result of that is two things:
 - response metadata/headers available immediately in "response"
 - response.entityBytes representing an async stream of potentially arriving body bytes (well, in fact in some cases this might be available already if the request is small enough so that we get the whole thing from TCP in one go)

-Endre


On Sat, Jul 16, 2016 at 1:03 AM, Dagny T <daphn...@gmail.com> wrote:
Hi there! Akka newbie. Trying to learn the latest Akka Http Streams API from this:http://www.lightbend.com/activator/template/akka-sample-twitter-streaming ; I'm running into bizarre behavior with that; and posted my list of questions and what I've tried in the Disqus comments just under that Template. Hoping someone with reliable current experience with the Akka Http Streams API could please help with suggestions for where to find answers to my questions, please. THANKS!

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
Akka Team
Lightbend - Reactive apps on the JVM
Twitter: @akkateam

Dagny T

unread,
Jul 23, 2016, 3:30:08 AM7/23/16
to Akka User List, daphn...@gmail.com

THANK YOU to the Akka Team for answering my questions; which I will need to go through tomorrow.
Reply all
Reply to author
Forward
0 new messages