Akka-http-请求和主机级别池的配置 [英] Akka-http - configuration of request and host-level pools

查看:188
本文介绍了Akka-http-请求和主机级别池的配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请求级API使用的超级池与主机级API创建的缓存池之间在池设置方面有什么关系?



<为了提供更多上下文,我需要使用快速响应的请求和更昂贵的请求来查询同一主机/端点。我当前的策略是对便宜的查询使用 Http()。singleRequest()和缓存的主机池来隔离较昂贵的查询。我想确保昂贵的查询不会耗尽超级池中所有可用的连接。



我是正确的,我希望它们的确会即使两个单独的池指向同一主机,它们也一样?如果是这样,是否有办法分别为超级池和缓存池配置最大连接数?我只在 reference.conf 文件中看到一种设置。

解决方案

就像@Stefano Bonetti所说的那样,一个简单的解决方法是通过配置强制akka-http使用不同的缓存池,例如,如果您使用singleRequest()API,则可以更改用户代理,然后akka为您创建不同的池, Java中的代码示例可以是:

  UserAgent userAgent = UserAgent.create(ProductVersion.create( akka-http, 1.0 ,actorPath)); 

ConnectionPoolSettings设置= ConnectionPoolSettings.create(context()。system())
.withConnectionSettings(ClientConnectionSettings.create(context()。system())
.withUserAgentHeader(可选.of(userAgent)));


http.singleRequest(httpRequest,http.defaultClientHttpsContext(),setting,context()。system()。log(),物化器)...。此处用于处理响应的代码


What is the relationship in terms of pool settings between the super-pool used by the Request-level API, and the cached pool created by the host-level API?

To provide more context: I need to query the same host/endpoint with fast, responsive requests, and with more expensive requests. My current strategy is to use Http().singleRequest() for the cheap queries, and a cached host-pool to "isolate" the more expensive queries. I want to make sure that the expensive queries won't use up all the connections available in the super-pool.

Am I right in my expectation that they will indeed be 2 separate pools even though they point to the same host? If so, is there a way to configure, say the max-connection count, for the super pool and for the cached pool separately? I only see one setting in the reference.conf file.

解决方案

As @Stefano Bonetti say, the easy workaround for this is to force akka-http use different cached pools by configuration, for example if you use singleRequest() api you can change the user-agent and then akka create diferent pools for you, a code example in java can be:

 UserAgent userAgent =  UserAgent.create(ProductVersion.create("akka-http", "1.0", actorPath));

    ConnectionPoolSettings setting = ConnectionPoolSettings.create(context().system())
            .withConnectionSettings(ClientConnectionSettings.create(context().system())
            .withUserAgentHeader(Optional.of(userAgent)));


    http.singleRequest(httpRequest, http.defaultClientHttpsContext(), setting, context().system().log(), materializer).... Here code to handle the response

这篇关于Akka-http-请求和主机级别池的配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆