azure-docs-sdk-java/docs-ref-autogen/com.azure.core.http.netty.yml

13 строки
4.5 KiB
YAML

### YamlMime:JavaPackage
uid: "com.azure.core.http.netty"
fullName: "com.azure.core.http.netty"
name: "com.azure.core.http.netty"
summary: "[ Azure Core Http Netty][Azure Core Http Netty] client library is a plugin for the azure-core HTTP client API.\n\n\n[Azure Core Http Netty]: https://learn.microsoft.com/java/api/overview/azure/core-http-netty-readme?view=azure-java-stable"
classes:
- "com.azure.core.http.netty.NettyAsyncHttpClientBuilder"
- "com.azure.core.http.netty.NettyAsyncHttpClientProvider"
desc: "[ Azure Core Http Netty][Azure Core Http Netty] client library is a plugin for the azure-core HTTP client API. It allows you to use Netty as the underlying HTTP client for communicating with Azure services. It is the default HTTP client used in all Azure SDK for Java libraries, but you can also replace it with other implementations such as OkHttp or the JDK 11 HttpClient. You can also configure various aspects of the Netty client, such as proxy, protocol, or chunk size. For more details refer to our [conceptual documentation][].\n\n**Sample: Construct NettyAsyncHttpClient with Default Configuration**\n\nThe following code sample demonstrates the creation of a Netty HttpClient that uses port 80 and has no proxy.\n\n```java\nHttpClient client = new NettyAsyncHttpClientBuilder().build();\n```\n\n--------------------\n\n## **Using NettyAsyncHttpClient with Http Proxy** ##\n\nConfiguring the Netty client with a proxy in the context of Azure Java SDK is relevant when your application needs to communicate with Azure services through a proxy server. For more details refer to our [conceptual documentation][conceptual documentation 1].\n\nThe following code sample demonstrates the creation of a Netty HttpClient that is using a proxy.\n\n```java\nHttpClient client = new NettyAsyncHttpClientBuilder()\n .proxy(new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress(\"<proxy-host>\", 8888)))\n .build();\n```\n\n--------------------\n\n## **Using NettyAsyncHttpClient with HTTP/2 Support** ##\n\nThe following code sample demonstrates the creation of a Netty HttpClient that supports both the HTTP/1.1 and HTTP/2 protocols, with HTTP/2 being the preferred protocol.\n\n```java\n// Constructs an HttpClient that supports both HTTP/1.1 and HTTP/2 with HTTP/2 being the preferred protocol.\n HttpClient client = new NettyAsyncHttpClientBuilder(reactor.netty.http.client.HttpClient.create()\n .protocol(HttpProtocol.HTTP11, HttpProtocol.H2))\n .build();\n```\n\nIt is also possible to create a Netty HttpClient that only supports HTTP/2.\n\n```java\n// Constructs an HttpClient that only supports HTTP/2.\n HttpClient client = new NettyAsyncHttpClientBuilder(reactor.netty.http.client.HttpClient.create()\n .protocol(HttpProtocol.H2))\n .build();\n```\n\n--------------------\n\n## Using NettyAsyncHttpClient with Custom Max Chunk Size ##\n\nThe adjustment of the max chunk size involves the modification of the maximum size of ByteBufs returned by Netty, subsequently converted to `ByteBuffer`. Altering the chunk size can yield positive performance effects, particularly notable in APIs like the download to file methods within Azure Storage libraries such as azure-storage-blob, azure-storage-file-datalake, and azure-storage-file-shares. Notably, improvements in performance have been consistently observed in the range of 32KB to 64KB.\n\nThe following code sample demonstrates the creation of a Netty HttpClient that uses a custom max chunk size.\n\n```java\n// Constructs an HttpClient with a modified max chunk size.\n // Max chunk size modifies the maximum size of ByteBufs returned by Netty (later converted to ByteBuffer).\n // Changing the chunk size can positively impact performance of APIs such as Storage's download to file methods\n // provided in azure-storage-blob, azure-storage-file-datalake, and azure-storage-file-shares (32KB - 64KB have\n // shown the most consistent improvement).\n HttpClient httpClient = new NettyAsyncHttpClientBuilder(reactor.netty.http.client.HttpClient.create()\n .httpResponseDecoder(httpResponseDecoderSpec -> httpResponseDecoderSpec.maxChunkSize(64 * 1024)))\n .build();\n```\n\n\n[Azure Core Http Netty]: https://learn.microsoft.com/java/api/overview/azure/core-http-netty-readme?view=azure-java-stable\n[conceptual documentation]: https://learn.microsoft.com/azure/developer/java/sdk/http-client-pipeline#http-clients\n[conceptual documentation 1]: https://learn.microsoft.com/azure/developer/java/sdk/proxying#http-proxy-configuration"
metadata: {}
package: "com.azure.core.http.netty"
artifact: com.azure:azure-core-http-netty:1.15.4