`detach()` not picking up `withDispatcher` dispatcher ?

257 views
Skip to first unread message

Oliver Schrenk

unread,
Nov 16, 2016, 9:12:14 AM11/16/16
to spray.io User List
Hi,

I'm trying to understand how dispatchers and execution context work and then especially how you can deal with blocking calls as an API I'm working with unfortunately uses a blocking MongoDB driver.

My idea was to wrap every call in the routing layer with a `detach()` directive, and use a custom dispatcher.

So I do

    implicit val system = ActorSystem("spray-pressure")
    val serviceCustom = system.actorOf(Props(classOf[RestActor]).withDispatcher("custom-dispatcher"),"rest-api-custom")
    IO(Http) ! Http.Bind(serviceCustom, interface = "127.0.0.1", port = 8081)

and then have

  detach() {
      complete {
        logger.info("Inside implicit detach complete")
        "Blocking Db driver" 
  } } 

I thought that this would pickup the custom dispatcher but it does not.

  2016-11-16 15:06:36,642 [default-akka.actor.default-dispatcher-7] [routes.DetachedRoute$$anonfun$2]  INFO - Blocking Db driver

I guess my question is why not? I mean I could set set the dispatcher explicitlyin the `detach()`.  But then what is that dispatcher defined in `withDispatcher` used for?

Cheers,
Oliver

PS 
Full project/code here: 
[spray-pressure/DetachedRoute.scala at custom-dispatcher · oschrenk/spray-pressure · GitHub](https://github.com/oschrenk/spray-pressure/blob/custom-dispatcher/src/main/scala/routes/DetachedRoute.scala)


Reply all
Reply to author
Forward
0 new messages