Using dispatcher with Spray HttpService

My application has an API using SprayCan. In the application, any lock 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 using its own dispatcher?

Is it also common practice to use a router for an API service to handle more requests?

class MyService extends Actor with HttpService {...} val service = system.actorOf(MyService.props(...).withDispatcher(???)) 
+1
source share
1 answer

Is it necessary to protect the API service from blocking the application by configuring it on its own Dispatcher too?

Usually not required. Check reference.conf , which comes as the default configuration with Spray, to make sure this dispatcher meets your needs. If not, specify a custom one.

Is it also common practice to use a router for an API service to handle large requests?

Typically, requests are forwarded to another Actor to unblock the route, or run as Future (possibly in a separate thread pool). See All Available Options Here: How is the .HttpService Atomization Request Performed? .

Finally, you should not block the route handler because it will block your service. From your description, it sounds like your lock code works in Future or similar. Until it forces the route handler to wait for the result / block it.

+1
source

Source: https://habr.com/ru/post/1246657/


All Articles