将Dispatcher与Spray HttpService一起使用

编程入门 行业动态 更新时间:2024-10-26 07:30:42
本文介绍了将Dispatcher与Spray HttpService一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的应用程序具有使用SprayCan的API。在应用程序中,任何阻塞代码都为每个特定资源都有一个单独的调度程序。

是否也需要通过使用自己的Dispatcher配置API服务来保护API服务免受应用程序的阻止?

使用Router进行API服务来处理更大容量的请求也是一种惯例吗?

类MyService使用HttpService扩展Actor {...} val service = system.actorOf(MyService.props(...)。withDispatcher(??? ))

解决方案

是吗

通常不是通过使用自己的Dispatcher配置API服务来防止应用程序阻止API服务吗?必要。使用Spray检查默认配置附带的 reference.conf ,看看该调度程序是否可以满足您的需求。如果不是这样,请提供自定义的。

另外,将路由器用于API服务的常见做法是处理一个请求容量更大吗? (可能在单独的线程池上)。在此处查看所有可用选项: spray.routing.HttpService调度请求如何? a>。

最后,您不应阻塞路由处理程序,因为它会阻塞您的服务。从您的描述看来,您的阻止代码运行在 Future 或类似版本中。只要它不使路由处理程序等待结果/阻止就可以了。

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(???))

解决方案

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.

更多推荐

将Dispatcher与Spray HttpService一起使用

本文发布于:2023-11-25 04:16:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628286.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Dispatcher   Spray   HttpService

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!