记得上下班打卡 | git大法好,push需谨慎
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liquidnet-bus-v1
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
董敬伟
liquidnet-bus-v1
Commits
9398113b
Commit
9398113b
authored
Jun 09, 2022
by
anjiabin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加okhttp配置类
parent
b4ec3b58
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
0 deletions
+62
-0
HttpUtil.java
...c/main/java/com/liquidnet/commons/lang/util/HttpUtil.java
+3
-0
RestTemplateOkConfig.java
...uidnet/commons/lang/util/spring/RestTemplateOkConfig.java
+54
-0
pom.xml
liquidnet-bus-common/pom.xml
+5
-0
No files found.
liquidnet-bus-common/liquidnet-common-base/src/main/java/com/liquidnet/commons/lang/util/HttpUtil.java
View file @
9398113b
...
...
@@ -19,7 +19,10 @@ public class HttpUtil {
private
static
final
RestTemplate
restTemplate
;
static
{
//apache httpClient
restTemplate
=
RestTemplateConfig
.
getRestTemplate
();
//okhttp3 client
// restTemplate = RestTemplateOkConfig.getRestTemplate();
}
/**
...
...
liquidnet-bus-common/liquidnet-common-base/src/main/java/com/liquidnet/commons/lang/util/spring/RestTemplateOkConfig.java
0 → 100644
View file @
9398113b
package
com
.
liquidnet
.
commons
.
lang
.
util
.
spring
;
import
okhttp3.ConnectionPool
;
import
okhttp3.OkHttpClient
;
import
org.springframework.http.client.ClientHttpRequestFactory
;
import
org.springframework.http.client.OkHttp3ClientHttpRequestFactory
;
import
org.springframework.web.client.RestTemplate
;
import
java.util.concurrent.TimeUnit
;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: RestTemplateOkConfig
* @Package com.liquidnet.commons.lang.util.spring
* @Copyright: LightNet @ Copyright (c) 2022
* @date 2022/6/9 11:56
*/
public
class
RestTemplateOkConfig
{
private
static
RestTemplate
restTemplate
;
static
{
long
startTime
=
System
.
currentTimeMillis
();
ConnectionPool
pool
=
new
ConnectionPool
(
500
,
5
,
TimeUnit
.
MINUTES
);
OkHttpClient
okHttpClient
=
new
OkHttpClient
().
newBuilder
()
.
connectionPool
(
pool
)
.
connectTimeout
(
2
,
TimeUnit
.
MINUTES
)
.
readTimeout
(
2
,
TimeUnit
.
MINUTES
)
.
writeTimeout
(
2
,
TimeUnit
.
MINUTES
)
.
hostnameVerifier
((
hostname
,
session
)
->
true
)
// 设置代理
// .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8888)))
// 拦截器
// .addInterceptor()
.
build
();
ClientHttpRequestFactory
factory
=
new
OkHttp3ClientHttpRequestFactory
(
okHttpClient
);
restTemplate
=
new
RestTemplate
(
factory
);
System
.
out
.
println
(
"初始化 RestTemplate,bean name :{}"
+
"restTemplate"
);
System
.
out
.
println
(
"初始化 ok RestTemplate总耗时"
+(
System
.
currentTimeMillis
()-
startTime
));
}
public
static
RestTemplate
getRestTemplate
(){
return
restTemplate
;
}
private
static
int
getMaxCpuCore
(){
int
cpuCore
=
Runtime
.
getRuntime
().
availableProcessors
();
return
cpuCore
;
}
}
liquidnet-bus-common/pom.xml
View file @
9398113b
...
...
@@ -77,6 +77,11 @@
<artifactId>
fst
</artifactId>
<version>
2.57
</version>
</dependency>
<dependency>
<groupId>
com.squareup.okhttp3
</groupId>
<artifactId>
okhttp
</artifactId>
<version>
4.9.3
</version>
</dependency>
</dependencies>
<dependencyManagement>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment