From bea16fe3b37653c865dd116b5d802b245c6420ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E9=A3=8E?= Date: Wed, 8 May 2024 17:58:25 +0800 Subject: [PATCH] feat: support set okhttpclient --- pom.xml | 6 ++-- tuya-api/pom.xml | 2 +- tuya-common/pom.xml | 2 +- tuya-messaging/pom.xml | 2 +- tuya-spring-boot-starter-sample/pom.xml | 2 +- .../sample/config/CustomOkHttpClient.java | 34 +++++++++++++++++++ tuya-spring-boot-starter/pom.xml | 2 +- 7 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 tuya-spring-boot-starter-sample/src/main/java/com/tuya/open/spring/boot/sample/config/CustomOkHttpClient.java diff --git a/pom.xml b/pom.xml index b25eb92..f5e7148 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.tuya tuya-connector pom - 1.3.5 + 1.4.0 tuya-api tuya-messaging @@ -17,9 +17,9 @@ 1.8 1.8 - 1.3.3 + 1.3.6 5.7.0 - 1.18.18 + 1.18.26 1.2.3 1.2.83 2.1.1.RELEASE diff --git a/tuya-api/pom.xml b/tuya-api/pom.xml index d97a409..65b2cca 100644 --- a/tuya-api/pom.xml +++ b/tuya-api/pom.xml @@ -6,7 +6,7 @@ com.tuya tuya-connector - 1.3.5 + 1.4.0 tuya-api diff --git a/tuya-common/pom.xml b/tuya-common/pom.xml index d252ee3..66a24be 100644 --- a/tuya-common/pom.xml +++ b/tuya-common/pom.xml @@ -6,7 +6,7 @@ com.tuya tuya-connector - 1.3.5 + 1.4.0 tuya-common diff --git a/tuya-messaging/pom.xml b/tuya-messaging/pom.xml index 391865a..e971519 100644 --- a/tuya-messaging/pom.xml +++ b/tuya-messaging/pom.xml @@ -6,7 +6,7 @@ com.tuya tuya-connector - 1.3.5 + 1.4.0 tuya-messaging diff --git a/tuya-spring-boot-starter-sample/pom.xml b/tuya-spring-boot-starter-sample/pom.xml index 7dad257..487ffdb 100644 --- a/tuya-spring-boot-starter-sample/pom.xml +++ b/tuya-spring-boot-starter-sample/pom.xml @@ -17,7 +17,7 @@ 17 - 1.3.3 + 1.4.0 diff --git a/tuya-spring-boot-starter-sample/src/main/java/com/tuya/open/spring/boot/sample/config/CustomOkHttpClient.java b/tuya-spring-boot-starter-sample/src/main/java/com/tuya/open/spring/boot/sample/config/CustomOkHttpClient.java new file mode 100644 index 0000000..ad3cb94 --- /dev/null +++ b/tuya-spring-boot-starter-sample/src/main/java/com/tuya/open/spring/boot/sample/config/CustomOkHttpClient.java @@ -0,0 +1,34 @@ +package com.tuya.open.spring.boot.sample.config; + +import jakarta.annotation.PostConstruct; +import lombok.extern.slf4j.Slf4j; +import okhttp3.Dispatcher; +import okhttp3.OkHttpClient; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.DependsOn; + +@Slf4j +@Configuration +public class CustomOkHttpClient implements ApplicationContextAware { + private static ApplicationContext ctx; + + + @PostConstruct + @DependsOn("tuyaConfiguration") + public void customSetOkHttpClient() { + log.info("自定义OkHttpClient..."); + com.tuya.connector.api.config.Configuration configuration = ctx.getBean(com.tuya.connector.api.config.Configuration.class); + Dispatcher dispatcher = new Dispatcher(); + dispatcher.setMaxRequestsPerHost(20); + OkHttpClient myOkHttpClient = new OkHttpClient.Builder().dispatcher(dispatcher).build(); + configuration.getApiDataSource().setSpecificClient(myOkHttpClient); + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + ctx = applicationContext; + } +} diff --git a/tuya-spring-boot-starter/pom.xml b/tuya-spring-boot-starter/pom.xml index ba149b9..7929fb9 100644 --- a/tuya-spring-boot-starter/pom.xml +++ b/tuya-spring-boot-starter/pom.xml @@ -6,7 +6,7 @@ tuya-connector com.tuya - 1.3.5 + 1.4.0 tuya-spring-boot-starter