Use a Dispatcher with Spray HttpService

纵饮孤独 提交于 2019-12-11 12:32:37

问题


My application has an API using SprayCan. In the application, any blocking code has a separate dispatcher for each specific resource.

Is it necessary to protect the API service from being blocked by the application by configuring it with it's own Dispatcher too?

Also is it common practice to use a Router for an API service to handle a larger capacity of requests?

 class MyService extends Actor with HttpService {...}

 val service = system.actorOf(MyService.props(...).withDispatcher(???))

回答1:


Is it necessary to protect the API service from being blocked by the application by configuring it with it's own Dispatcher too?

Usually not necessary. Check reference.conf that comes as default config with Spray to see if that dispatcher will satisfy your needs. If not, provide a custom one.

Also is it common practice to use a Router for an API service to handle a larger capacity of requests?

Usually requests are handed off to another Actor to unblock the route or ran as Future (possibly on a separate thread pool). See all available options here: How does spray.routing.HttpService dispatch requests?.

Finally, you should not block in the route handler because it will block your service. From your description it sounds like your blocking code runs in a Future or similar. As long as it does not make route handler wait for result/block it's fine.



来源:https://stackoverflow.com/questions/34298233/use-a-dispatcher-with-spray-httpservice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!