我对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连接池
发布评论