Akka Streams: Implementing handshake/authentication/etc

126 views
Skip to first unread message

Ryon Day

unread,
Sep 23, 2016, 6:33:42 PM9/23/16
to Akka User List
Hello! A few quick questions. I've gone over all of the available examples for Akka Streams, and I have not yet been able to find anything about two use cases:

Doing something one time per stream upon connection.

Currently I'm trying to implement a primitive IRC client using Akka-Streams. This requires, ONCE upon connection to send a nickname and an optional password, and the server will reply. For the life of me, I cannot find anything that would tell me how to do this seemingly common use case. All examples (such as the echo server etc) seem to concentrate on doing either one thing, or every one of a series of steps for the life of a stream. There seems to be nothing to tell a particular flow step to execute only once and to say, terminate the stream upon indication of failure.

I also have seen nothing about automatically re-running a stream if a connection is interrupted. 

Apologies if this has been gone over, but none of the documentation or examples seem to be particularly helpful in this regard. Is Akka-Streams not the correct choice for modeling protocols that have different stages to them? am I conceptually missing something here?

Thank you!

gor...@8kdata.com

unread,
Sep 27, 2016, 5:27:37 AM9/27/16
to Akka User List
I am an Akka Stream newbie and this kind of problems is the main reason why we are not using Akka Streams more widely. I also feel the lack of documentation in this kind of cases.

A solution I can imagine is to have two sources, one of them used when the connection is not handshaked and the other one after that. Then, you can merge both streams and finally your code should decide where to send the request.

James Matlik

unread,
Sep 27, 2016, 6:48:33 AM9/27/16
to akka...@googlegroups.com

It is hard to give much input without knowing the state of the code you want to add this one time activity into. I'm inclined to think you could use a factory function that accepts the credentials and returns a stream. Have a special case message be processed at the start by prepending it, thus processing it first. You may need to enrich the types at the start of the stream to drive the special handling logic, such as wrapping in 'either' or donation specific case classes.

Hope this helps,
James


--
>>>>>>>>>> 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+unsubscribe@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.

Ryon Day

unread,
Sep 27, 2016, 3:40:44 PM9/27/16
to Akka User List
Thanks for the reply!

I'm trying to learn Akka streams by green fielding this project (typically I like to learn new things by trying to make something useful). So I guess what I'm asking is whether or not there's an accepted pattern to establishing a steady state of a Stream. More generally, it stands to reason that streams can have different 'stages'. So in the case of an IRC client bot:

1. Connect
2. Send credentials
3. Establish nickname
4. Join any channels
5. Begin processing messages.

For the above, 1-4 are done only once, and step 5 is the "steady state". For the life of me, I cannot figure out an effective or elegant way to express this functionality using Akka streams. Steps 1-4 are connected to 5, and are prerequisites for 5, but the interaction with the endpoint is handled completely differently. 

It feels like the majority of useful work with say, TCP and WebSocket streams would be structured in this way but I haven't found any examples of implementing this pattern with Akka-Streams, which is odd because it seems so incredibly useful (the Javascript web API has a onOpen() method on its web socket that is called upon the establishment of a connection, for instance). 

Still confused; thank you for the help!
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages