Hi guys,

I was wondering what is the best practice used in Akka Streams to clean up 
opened resources. My example use case is the stream reading lines from the 
file, streaming them to Apache Kafka 
(using https://github.com/softwaremill/reactive-kafka subscriber). See the 
example code here:

val file = io.Source.fromFile(path)
val lines = file.getLines()
val kafka = new ReactiveKafka(host = "localhost:9092", zooKeeperHost = 
"localhost:2181")
val subscriber = kafka.publish("uppercaseStrings", "groupName", new 
StringEncoder())

Source(() => lines)
  .map(_.toUpperCase)
  .to(Sink(subscriber))
  .run()


As soon as the flow is done I would like to cleanup and close the file 
input stream. One way I used to go about that is to have Sink.onComplete or 
Sink.fold although this is not viable here. Also, ideally I would like to 
close the file in case of any error. 

Could you advice on any idiomatic way to do this? 

Thanks,
~Petr

 

-- 
>>>>>>>>>>      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 http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to