Skip to content

Commit

Permalink
feat: support set okhttpclient
Browse files Browse the repository at this point in the history
  • Loading branch information
tuya-qiufeng committed May 8, 2024
1 parent a608ac2 commit bea16fe
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.tuya</groupId>
<artifactId>tuya-connector</artifactId>
<packaging>pom</packaging>
<version>1.3.5</version>
<version>1.4.0</version>
<modules>
<module>tuya-api</module>
<module>tuya-messaging</module>
Expand All @@ -17,9 +17,9 @@
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<connector.version>1.3.3</connector.version>
<connector.version>1.3.6</connector.version>
<junit-jupiter.version>5.7.0</junit-jupiter.version>
<lombok.version>1.18.18</lombok.version>
<lombok.version>1.18.26</lombok.version>
<logback.version>1.2.3</logback.version>
<fastjson.version>1.2.83</fastjson.version>
<spring-boot.version>2.1.1.RELEASE</spring-boot.version>
Expand Down
2 changes: 1 addition & 1 deletion tuya-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.tuya</groupId>
<artifactId>tuya-connector</artifactId>
<version>1.3.5</version>
<version>1.4.0</version>
</parent>

<artifactId>tuya-api</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion tuya-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.tuya</groupId>
<artifactId>tuya-connector</artifactId>
<version>1.3.5</version>
<version>1.4.0</version>
</parent>

<artifactId>tuya-common</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion tuya-messaging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.tuya</groupId>
<artifactId>tuya-connector</artifactId>
<version>1.3.5</version>
<version>1.4.0</version>
</parent>

<artifactId>tuya-messaging</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion tuya-spring-boot-starter-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<properties>
<java.version>17</java.version>
<tuya-spring-boot-starter.version>1.3.3</tuya-spring-boot-starter.version>
<tuya-spring-boot-starter.version>1.4.0</tuya-spring-boot-starter.version>
</properties>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 1 addition & 1 deletion tuya-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>tuya-connector</artifactId>
<groupId>com.tuya</groupId>
<version>1.3.5</version>
<version>1.4.0</version>
</parent>

<artifactId>tuya-spring-boot-starter</artifactId>
Expand Down

0 comments on commit bea16fe

Please sign in to comment.