Hi Chhil,

The flow returned by outgoingConnection materializes into a 
CompletionStage<OutgoingConnection> which will be failed if the connection 
fails, so that is where you can implement your error handling for the 
initial connection. You would have to keep the materialized value when you 
construct the flow though, so that it is returned from run(). 

You can read more about materialized values 
here: 
http://doc.akka.io/docs/akka/2.4/java/stream/stream-composition.html#materialized-values
 
and TCP with streams here: 
http://doc.akka.io/docs/akka/2.4/java/stream/stream-io.html#stream-io-java  

In general, read as much of the streams docs as you can to get a good 
understanding of how Akka Streams work, trial and error with streams + tcp 
will hurt!

--
Johan
Akka Team

On Monday, August 1, 2016 at 7:20:23 AM UTC+2, murtuza chhil wrote:
>
> Hello,
>
> I am a newbie trying to understand Akka Streams.
>
> Coming from regular socket programming I am trying to mimic a client 
> connection and have the following runnable graph.
>
>         Flow<ByteString, ByteString, CompletionStage<OutgoingConnection>> 
> flow = Tcp
>                 .get(system).outgoingConnection("127.0.0.1", 6000);
>         Source<ByteString, NotUsed> clientSource = Source.single(ByteString
>                 .fromString("XYZ"));
>
>         clientSource.via(flow).to(Sink.ignore()).run(mat);
>
> ​
>
> This works fine when used with the samples in the doc, where the source is 
> attached that has a list and there is a server listening and we run the 
> source->flow->sink through a materializer.
>
> But this is not a typical use case, typically one would attempt to connect 
> to a server,  and either it connects or fails. If connected send data that 
> will be made available and if connection fails, have the ability to backoff.
>
>
> Currently I don't know how to access the error when a server is not 
> available and want to establish a connection before data is available.
> Don't know how to prevent connections every time data is sent, I 
> understand why it happens, but don't know how to reuse a materialized flow 
> that has already connected.
> What I am trying to get my head around is how does one run a graph without 
> any source data and get a completable future that tells me if it succeeded 
> or not.
> Then I want to use the same connection to send data later using the source.
>
> I have attempted with a runfold and that give me the akka TCP Exception 
> when the server is not availble, but I simply want to forward the data from 
> the source without manipulation.
>
> There was another thread that I had started 
> https://groups.google.com/d/msg/akka-user/1ztizMy9FnI/U9toR-cOBgAJ, would 
> appreciate if someone responds to it. 
>
> Any pointers or snippets would be greatly appreciated. Yes I am not used 
> to this paradigm of programming but trying to figure it out.
>
> -chhil
>
>

-- 
>>>>>>>>>>      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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to