Restlet HTTP连接池

编程入门 行业动态 更新时间:2024-10-28 20:27:19
本文介绍了Restlet HTTP连接池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对Restlet相当陌生,并编写了一小段代码来进行HTTP调用.它正在工作,但是我想知道如何向其中添加HTTP连接池(Apache). 我找不到任何教程或参考代码.

I am fairly new to Restlet and wrote small piece of code to make a HTTP call. It is working but I was wondering how can I add HTTP Connection pooling (apache) into it. I am not able to find any tutorial or reference code for it.

Client client = new Client(Protocol.HTTP); ChallengeResponse challengeResponse = new ChallengeResponse( ChallengeScheme.HTTP_AZURE_SHAREDKEY, acctName, accKey); String url = RestHelper.createRequestURI("CCC"); Request request = new Request(Method.GET, url); request.setChallengeResponse(challengeResponse); Response response = client.handle(request);

任何参考或帮助将不胜感激.

Any references or help will be appreciated.

推荐答案

实际上,Restlet在客户端连接器级别内部管理池.可以使用客户端的上下文来配置此池.以下示例介绍了如何配置它:

In fact, Restlet internally manages a pool at the client connector level. Configuration of this pool can be done using the context of your client. The following example describes to configure it:

Client client = new Client(new Context(), Protocol.HTTP); client.getContext().getParameters().add("maxConnectionsPerHost","5"); client.getContext().getParameters().add("maxTotalConnections","5");

您会注意到这些参数取决于您使用的基础客户端连接器.

You can notice that these parameters depend on the underlying client connector you use.

以下是一些有用的链接:

Here are some helpful links:

  • 与连接器有关的文档: restlet /technical-resources/restlet-framework/guide/2.3/core/base/connectors
  • 包含用于HTTP客户端连接器的参数的Javadoc: restlet/technical-resources/restlet-framework/javadocs/2.3/jse/ext/org/restlet/ext/httpclient/HttpClientHelper.html
  • Doc related to connectors: restlet/technical-resources/restlet-framework/guide/2.3/core/base/connectors
  • Javadoc containing parameters for the HTTP client connector: restlet/technical-resources/restlet-framework/javadocs/2.3/jse/ext/org/restlet/ext/httpclient/HttpClientHelper.html

请注意,如果使用ClientResource,则需要共享同一客户端,以使客户端连接器只有一个实例.否则,将为每个请求实例化一个新请求.请在下面查看实现此方法的方法:

Notice that if you use ClientResource, you need to share the same client to have only one instance of the client connector under the hood. Otherwise a new one is instantiated for each request. See the way to implement this below:

Client client = new Client(new Context(), Protocol.HTTP); ClientResource cr = new ClientResource("myurl"); cr.setNext(client);

希望有帮助, 蒂埃里

更多推荐

Restlet HTTP连接池

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

发布评论

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

>www.elefans.com

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