I would really appreciate any tips for the correct direction 

On Thursday, July 23, 2015 at 3:02:54 PM UTC+3, ra...@qmerce.com wrote:
>
> I am implementing a simple http server which listens to requests and 
> persists them to Cassandra.
>
>  I have to split the stream in two using Broadcast so I am using Graphs. 
>
> I have something like this:
>
> val bindingFuture: Future[Http.ServerBinding] =
>>   source.serverSource.to(Sink.foreach { connection => // foreach 
>> materializes the source
>>     system.log.debug("Accepted new connection from " + 
>> connection.remoteAddress)
>>     // ... and then actually handle the connection
>>     connection.handleWith(source.handleRequests)(server_materializer)
>>   }).run()(server_materializer)
>>
>>
>
> And also 
>
>> val handleRequests = 
>> Flow[HttpRequest].mapAsyncUnordered(core.num_of_cores)(v => 
>> Future(requestHandler(v)))
>>
>>  
>
>> val requestHandler: HttpRequest => HttpResponse = {
>> case HttpRequest(POST, Uri.Path("/stats"), headers, entity, protocol) =>
>>
>>
>> val s = 
>> entity.withContentType(ContentTypes.`application/json`).getDataBytes()
>> val g = FlowGraph.closed() { implicit builder =>
>>
>> import FlowGraph.Implicits._
>> //....Bla bla bla...
>>
>>
>>       s ~> gflow  ~> bcast ~> breakEvent ~> persistToC ~> out
>>       bcast ~> out
>>
>>     }
>>     g.run()
>>
>>     HttpResponse(200,headers = corsHeaders, entity = "Thanks!")
>>
>>   case _: HttpRequest =>
>>     HttpResponse(404, entity = "Unknown resource!")
>> }
>>
>>
> I am calling `.run` twice and from what I understand a new stream will be 
> initiated for each request. 
>
> My plan is to setup an actor that will publish the entities downstream, 
> However I am not sure this is the correct approach.
>
> Thanks in advance, 
>
> Raam 
>  
>

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

Reply via email to