-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a608ac2
commit bea16fe
Showing
7 changed files
with
42 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...rter-sample/src/main/java/com/tuya/open/spring/boot/sample/config/CustomOkHttpClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters