Re: [akka-user] problem connecting with TCP for file IO

2016-07-16 Thread debasish
Thanks for the pointer Konrad .. the Source.maybe worked .. Source.empty used 
to work earlier :-)

On Sunday, July 17, 2016 at 1:41:53 AM UTC+5:30, Konrad Malawski wrote:
>
> Not very online today, may look into it in more depth tomorrow but at a 
> glance it seems that you complete the connection too eagerly: instead of 
> Source.empty use Source.maybe (does not immediately send completion; 
> completion == closing the connection).
>
> Also, you don't need the GraphDSL, you can simply from.via(thingy) etc.
>
> Hope that's it, if not let me know and will have a proper look tomorrow.
> Cheers
>
> -- 
> Konrad Malawski
>
> From: debasish  
> Reply: akka...@googlegroups.com   
> 
> Date: 16 July 2016 at 21:59:30
> To: Akka User List  
> Subject:  [akka-user] problem connecting with TCP for file IO 
>
> Hi - 
>>
>> I am using akka-stream 2.4.8 for a use case which used to work properly 
>> with earlier version of akka-stream (1.x). It has a client that connects 
>> over TCP, streams a csv file to a server. The server receives the stream, 
>> parses the csv record and builds some domain object. 
>>
>> The issue that I am facing right now is that the server starts 
>> successfully. But when I run the client I get exceptions like 
>> Failure(akka.stream.StreamTcpException: 
>> The connection closed with error: Connection reset by peer).
>>
>> Here's the client code ..
>>
>> object Client extends App with Logging {
>>   implicit val system = ActorSystem("client")
>>   val serverConnection = Tcp().outgoingConnection("127.0.0.1", 9982)
>>   val path = 
>> "/Users/debasishghosh/projects/frdomain/src/main/resources/transactions.csv"
>>   val readLines =
>>   FileIO.fromPath(Paths.get(path))
>> .via(Framing.delimiter(ByteString(System.lineSeparator), 
>> maximumFrameLength = 512, allowTruncation = true))
>>   val logWhenComplete = Sink.onComplete(r => logger.info("Transfer 
>> complete: " + r))
>>   val graph = RunnableGraph.fromGraph(GraphDSL.create() { implicit b =>
>> import GraphDSL.Implicits._
>> readLines ~> serverConnection ~> logWhenComplete
>> ClosedShape
>>   })
>>   implicit val mat = ActorMaterializer()
>>   graph.run()
>> }
>>
>> ..and here's the server code ..
>>
>> class Server(host: String, port: Int)(implicit val system: ActorSystem) 
>> extends Logging {
>>   def run(): Unit = {
>> implicit val mat = ActorMaterializer()
>> logger.info(s"Receiver: binding to $host:$port")
>> Tcp().bind(host, port).runForeach { conn =>
>>   val receiveSink = 
>> conn.flow
>> .via(Framing.delimiter(ByteString(System.lineSeparator), 
>> maximumFrameLength = 512, allowTruncation = true)).map(_.utf8String)
>> .map(_.split(","))
>> .mapConcat(Transaction(_).toList)
>> .to(Sink.foreach[Transaction](println(_)))
>>   receiveSink.runWith(Source.empty)
>> }
>>   }
>> }
>>
>> object Server extends App {
>>   implicit val system = ActorSystem("processor")
>>   new Server("127.0.0.1", 9982).run()
>> }
>>
>>
>> Any help will be appreciated. I have attached the full files for client 
>> and server in case you want to run. The file path is currently hardcoded 
>> and needs to be changed there.
>>
>> 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.
>> --
>>
>

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


Re: [akka-user] problem connecting with TCP for file IO

2016-07-16 Thread Konrad Malawski
Not very online today, may look into it in more depth tomorrow but at a
glance it seems that you complete the connection too eagerly: instead of
Source.empty use Source.maybe (does not immediately send completion;
completion == closing the connection).

Also, you don't need the GraphDSL, you can simply from.via(thingy) etc.

Hope that's it, if not let me know and will have a proper look tomorrow.
Cheers

-- 
Konrad Malawski

From: debasish  
Reply: akka-user@googlegroups.com 

Date: 16 July 2016 at 21:59:30
To: Akka User List  
Subject:  [akka-user] problem connecting with TCP for file IO

Hi -
>
> I am using akka-stream 2.4.8 for a use case which used to work properly
> with earlier version of akka-stream (1.x). It has a client that connects
> over TCP, streams a csv file to a server. The server receives the stream,
> parses the csv record and builds some domain object.
>
> The issue that I am facing right now is that the server starts
> successfully. But when I run the client I get exceptions like 
> Failure(akka.stream.StreamTcpException:
> The connection closed with error: Connection reset by peer).
>
> Here's the client code ..
>
> object Client extends App with Logging {
>   implicit val system = ActorSystem("client")
>   val serverConnection = Tcp().outgoingConnection("127.0.0.1", 9982)
>   val path =
> "/Users/debasishghosh/projects/frdomain/src/main/resources/transactions.csv"
>   val readLines =
>   FileIO.fromPath(Paths.get(path))
> .via(Framing.delimiter(ByteString(System.lineSeparator),
> maximumFrameLength = 512, allowTruncation = true))
>   val logWhenComplete = Sink.onComplete(r => logger.info("Transfer
> complete: " + r))
>   val graph = RunnableGraph.fromGraph(GraphDSL.create() { implicit b =>
> import GraphDSL.Implicits._
> readLines ~> serverConnection ~> logWhenComplete
> ClosedShape
>   })
>   implicit val mat = ActorMaterializer()
>   graph.run()
> }
>
> ..and here's the server code ..
>
> class Server(host: String, port: Int)(implicit val system: ActorSystem)
> extends Logging {
>   def run(): Unit = {
> implicit val mat = ActorMaterializer()
> logger.info(s"Receiver: binding to $host:$port")
> Tcp().bind(host, port).runForeach { conn =>
>   val receiveSink =
> conn.flow
> .via(Framing.delimiter(ByteString(System.lineSeparator),
> maximumFrameLength = 512, allowTruncation = true)).map(_.utf8String)
> .map(_.split(","))
> .mapConcat(Transaction(_).toList)
> .to(Sink.foreach[Transaction](println(_)))
>   receiveSink.runWith(Source.empty)
> }
>   }
> }
>
> object Server extends App {
>   implicit val system = ActorSystem("processor")
>   new Server("127.0.0.1", 9982).run()
> }
>
>
> Any help will be appreciated. I have attached the full files for client
> and server in case you want to run. The file path is currently hardcoded
> and needs to be changed there.
>
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to akka-user@googlegroups.com.
> Visit this group at https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
> --
>

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


[akka-user] problem connecting with TCP for file IO

2016-07-16 Thread debasish
Hi -

I am using akka-stream 2.4.8 for a use case which used to work properly 
with earlier version of akka-stream (1.x). It has a client that connects 
over TCP, streams a csv file to a server. The server receives the stream, 
parses the csv record and builds some domain object. 

The issue that I am facing right now is that the server starts 
successfully. But when I run the client I get exceptions like 
Failure(akka.stream.StreamTcpException: 
The connection closed with error: Connection reset by peer).

Here's the client code ..

object Client extends App with Logging {
  implicit val system = ActorSystem("client")
  val serverConnection = Tcp().outgoingConnection("127.0.0.1", 9982)
  val path = 
"/Users/debasishghosh/projects/frdomain/src/main/resources/transactions.csv"
  val readLines =
  FileIO.fromPath(Paths.get(path))
.via(Framing.delimiter(ByteString(System.lineSeparator), 
maximumFrameLength = 512, allowTruncation = true))
  val logWhenComplete = Sink.onComplete(r => logger.info("Transfer 
complete: " + r))
  val graph = RunnableGraph.fromGraph(GraphDSL.create() { implicit b =>
import GraphDSL.Implicits._
readLines ~> serverConnection ~> logWhenComplete
ClosedShape
  })
  implicit val mat = ActorMaterializer()
  graph.run()
}

..and here's the server code ..

class Server(host: String, port: Int)(implicit val system: ActorSystem) 
extends Logging {
  def run(): Unit = {
implicit val mat = ActorMaterializer()
logger.info(s"Receiver: binding to $host:$port")
Tcp().bind(host, port).runForeach { conn =>
  val receiveSink = 
conn.flow
.via(Framing.delimiter(ByteString(System.lineSeparator), 
maximumFrameLength = 512, allowTruncation = true)).map(_.utf8String)
.map(_.split(","))
.mapConcat(Transaction(_).toList)
.to(Sink.foreach[Transaction](println(_)))
  receiveSink.runWith(Source.empty)
}
  }
}

object Server extends App {
  implicit val system = ActorSystem("processor")
  new Server("127.0.0.1", 9982).run()
}


Any help will be appreciated. I have attached the full files for client and 
server in case you want to run. The file path is currently hardcoded and 
needs to be changed there.

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


Client.scala
Description: Binary data


package.scala
Description: Binary data


Server.scala
Description: Binary data