Forráskód Böngészése

update 优化 将crt客户端替换为Netty客户端 节约17M打包大小

疯狂的狮子Li 1 hónapja
szülő
commit
bfc73ed214

+ 6 - 7
pom.xml

@@ -42,7 +42,6 @@
 
         <!-- OSS 配置 -->
         <aws.sdk.version>2.28.22</aws.sdk.version>
-        <aws.crt.version>0.31.3</aws.crt.version>
         <!-- SMS 配置 -->
         <sms4j.version>3.3.3</sms4j.version>
         <!-- 限制框架中的fastjson版本 -->
@@ -245,18 +244,18 @@
                 <artifactId>s3</artifactId>
                 <version>${aws.sdk.version}</version>
             </dependency>
-            <!-- 使用AWS基于 CRT 的 S3 客户端 -->
-            <dependency>
-                <groupId>software.amazon.awssdk.crt</groupId>
-                <artifactId>aws-crt</artifactId>
-                <version>${aws.crt.version}</version>
-            </dependency>
             <!-- 基于 AWS CRT 的 S3 客户端的性能增强的 S3 传输管理器 -->
             <dependency>
                 <groupId>software.amazon.awssdk</groupId>
                 <artifactId>s3-transfer-manager</artifactId>
                 <version>${aws.sdk.version}</version>
             </dependency>
+            <!-- 将基于 Netty 的 HTTP 客户端从类路径中移除 -->
+            <dependency>
+                <groupId>software.amazon.awssdk</groupId>
+                <artifactId>netty-nio-client</artifactId>
+                <version>${aws.sdk.version}</version>
+            </dependency>
             <!--短信sms4j-->
             <dependency>
                 <groupId>org.dromara.sms4j</groupId>

+ 3 - 8
ruoyi-common/ruoyi-common-oss/pom.xml

@@ -31,11 +31,6 @@
             <groupId>software.amazon.awssdk</groupId>
             <artifactId>s3</artifactId>
             <exclusions>
-                <!-- 将基于 Netty 的 HTTP 客户端从类路径中移除 -->
-                <exclusion>
-                    <groupId>software.amazon.awssdk</groupId>
-                    <artifactId>netty-nio-client</artifactId>
-                </exclusion>
                 <!-- 将基于 CRT 的 HTTP 客户端从类路径中移除 -->
                 <exclusion>
                     <groupId>software.amazon.awssdk</groupId>
@@ -54,10 +49,10 @@
             </exclusions>
         </dependency>
 
-        <!-- 使用AWS基于 CRT 的 S3 客户端 -->
+        <!-- 将基于 Netty 的 HTTP 客户端从类路径中移除 -->
         <dependency>
-            <groupId>software.amazon.awssdk.crt</groupId>
-            <artifactId>aws-crt</artifactId>
+            <groupId>software.amazon.awssdk</groupId>
+            <artifactId>netty-nio-client</artifactId>
         </dependency>
 
         <!-- 基于 AWS CRT 的 S3 客户端的性能增强的 S3 传输管理器 -->

+ 19 - 9
ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/core/OssClient.java

@@ -16,10 +16,10 @@ import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
 import software.amazon.awssdk.core.ResponseInputStream;
 import software.amazon.awssdk.core.async.AsyncResponseTransformer;
 import software.amazon.awssdk.core.async.BlockingInputStreamAsyncRequestBody;
+import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
 import software.amazon.awssdk.regions.Region;
 import software.amazon.awssdk.services.s3.S3AsyncClient;
 import software.amazon.awssdk.services.s3.S3Configuration;
-import software.amazon.awssdk.services.s3.crt.S3CrtHttpConfiguration;
 import software.amazon.awssdk.services.s3.model.GetObjectResponse;
 import software.amazon.awssdk.services.s3.presigner.S3Presigner;
 import software.amazon.awssdk.transfer.s3.S3TransferManager;
@@ -84,18 +84,28 @@ public class OssClient {
             // MinIO 使用 HTTPS 限制使用域名访问,站点填域名。需要启用路径样式访问
             boolean isStyle = !StringUtils.containsAny(properties.getEndpoint(), OssConstant.CLOUD_SERVICE);
 
-            // 创建AWS基于 CRT 的 S3 客户端
-            this.client = S3AsyncClient.crtBuilder()
+//            // 创建AWS基于 CRT 的 S3 客户端
+//            this.client = S3AsyncClient.crtBuilder()
+//                .credentialsProvider(credentialsProvider)
+//                .endpointOverride(URI.create(getEndpoint()))
+//                .region(of())
+//                .targetThroughputInGbps(20.0)
+//                .minimumPartSizeInBytes(10 * 1025 * 1024L)
+//                .checksumValidationEnabled(false)
+//                .forcePathStyle(isStyle)
+//                .httpConfiguration(S3CrtHttpConfiguration.builder()
+//                    .connectionTimeout(Duration.ofSeconds(60)) // 设置连接超时
+//                    .build())
+//                .build();
+
+            // 创建AWS基于 Netty 的 S3 客户端
+            this.client = S3AsyncClient.builder()
                 .credentialsProvider(credentialsProvider)
                 .endpointOverride(URI.create(getEndpoint()))
                 .region(of())
-                .targetThroughputInGbps(20.0)
-                .minimumPartSizeInBytes(10 * 1025 * 1024L)
-                .checksumValidationEnabled(false)
                 .forcePathStyle(isStyle)
-                .httpConfiguration(S3CrtHttpConfiguration.builder()
-                    .connectionTimeout(Duration.ofSeconds(60)) // 设置连接超时
-                    .build())
+                .httpClient(NettyNioAsyncHttpClient.builder()
+                    .connectionTimeout(Duration.ofSeconds(60)).build())
                 .build();
 
             //AWS基于 CRT 的 S3 AsyncClient 实例用作 S3 传输管理器的底层客户端