Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
谢明辉
/
VVAS-Match
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit fb433408
authored
Sep 02, 2024
by
姚冰
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[chg] 添加es配置参数
1 parent
1ea49831
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
204 additions
and
2 deletions
src/main/java/com/viontech/match/config/CustomElasticsearchProperties.java
src/main/java/com/viontech/match/config/ElasticsearchConfiguration.java
src/main/resources/application-option.properties
src/main/java/com/viontech/match/config/CustomElasticsearchProperties.java
0 → 100644
View file @
fb43340
package
com
.
viontech
.
match
.
config
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
public
class
CustomElasticsearchProperties
{
/**
* Comma-separated list of the Elasticsearch instances to use.
*/
private
List
<
String
>
uris
=
new
ArrayList
<>(
Collections
.
singletonList
(
"http://localhost:9200"
));
/**
* Username for authentication with Elasticsearch.
*/
private
String
username
;
/**
* Password for authentication with Elasticsearch.
*/
private
String
password
;
/**
* Connection timeout used when communicating with Elasticsearch.
*/
private
int
connectionTimeout
=
1
;
/**
* Socket timeout used when communicating with Elasticsearch.
*/
private
int
socketTimeout
=
30
;
/**
* Prefix added to the path of every request sent to Elasticsearch.
*/
private
String
pathPrefix
;
private
boolean
customized
=
false
;
private
Integer
ioThreadCount
;
private
Integer
maxConnTotal
;
private
Integer
maxConnPerRoute
;
public
List
<
String
>
getUris
()
{
return
this
.
uris
;
}
public
void
setUris
(
List
<
String
>
uris
)
{
customized
=
true
;
this
.
uris
=
uris
;
}
public
String
getUsername
()
{
return
this
.
username
;
}
public
void
setUsername
(
String
username
)
{
customized
=
true
;
this
.
username
=
username
;
}
public
String
getPassword
()
{
return
this
.
password
;
}
public
void
setPassword
(
String
password
)
{
customized
=
true
;
this
.
password
=
password
;
}
public
int
getConnectionTimeout
()
{
return
this
.
connectionTimeout
;
}
public
void
setConnectionTimeout
(
int
connectionTimeout
)
{
customized
=
true
;
this
.
connectionTimeout
=
connectionTimeout
;
}
public
int
getSocketTimeout
()
{
return
this
.
socketTimeout
;
}
public
void
setSocketTimeout
(
int
socketTimeout
)
{
customized
=
true
;
this
.
socketTimeout
=
socketTimeout
;
}
public
String
getPathPrefix
()
{
return
this
.
pathPrefix
;
}
public
void
setPathPrefix
(
String
pathPrefix
)
{
customized
=
true
;
this
.
pathPrefix
=
pathPrefix
;
}
public
boolean
isCustomized
()
{
return
customized
;
}
public
Integer
getIoThreadCount
()
{
return
ioThreadCount
;
}
public
void
setIoThreadCount
(
Integer
ioThreadCount
)
{
this
.
ioThreadCount
=
ioThreadCount
;
}
public
Integer
getMaxConnTotal
()
{
return
maxConnTotal
;
}
public
void
setMaxConnTotal
(
Integer
maxConnTotal
)
{
this
.
maxConnTotal
=
maxConnTotal
;
}
public
Integer
getMaxConnPerRoute
()
{
return
maxConnPerRoute
;
}
public
void
setMaxConnPerRoute
(
Integer
maxConnPerRoute
)
{
this
.
maxConnPerRoute
=
maxConnPerRoute
;
}
}
src/main/java/com/viontech/match/config/ElasticsearchConfiguration.java
0 → 100644
View file @
fb43340
package
com
.
viontech
.
match
.
config
;
import
org.apache.http.HttpHost
;
import
org.apache.http.auth.AuthScope
;
import
org.apache.http.auth.UsernamePasswordCredentials
;
import
org.apache.http.client.CredentialsProvider
;
import
org.apache.http.impl.client.BasicCredentialsProvider
;
import
org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager
;
import
org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor
;
import
org.apache.http.impl.nio.reactor.IOReactorConfig
;
import
org.apache.http.nio.reactor.IOReactorException
;
import
org.elasticsearch.client.RestClient
;
import
org.elasticsearch.client.RestClientBuilder
;
import
org.elasticsearch.client.RestHighLevelClient
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.StringUtils
;
@Component
public
class
ElasticsearchConfiguration
{
@Bean
@ConfigurationProperties
(
prefix
=
"spring.elasticsearch.rest"
)
public
CustomElasticsearchProperties
Properties
()
{
return
new
CustomElasticsearchProperties
();
}
@Bean
public
RestHighLevelClient
createClient
(
CustomElasticsearchProperties
properties
)
{
HttpHost
[]
esHosts
=
properties
.
getUris
().
stream
().
filter
(
StringUtils:
:
hasLength
).
map
(
HttpHost:
:
create
).
toArray
(
HttpHost
[]::
new
);
final
CredentialsProvider
credentialsProvider
=
new
BasicCredentialsProvider
();
if
(
properties
.
getUsername
()
!=
null
)
{
credentialsProvider
.
setCredentials
(
AuthScope
.
ANY
,
new
UsernamePasswordCredentials
(
properties
.
getUsername
(),
properties
.
getPassword
()));
}
final
IOReactorConfig
ioReactorConfig
=
IOReactorConfig
.
custom
().
setIoThreadCount
(
properties
.
getIoThreadCount
()).
setConnectTimeout
(
10
).
setRcvBufSize
(
5
).
setSoKeepAlive
(
true
).
build
();
PoolingNHttpClientConnectionManager
connectionManager
=
null
;
try
{
connectionManager
=
new
PoolingNHttpClientConnectionManager
(
new
DefaultConnectingIOReactor
(
ioReactorConfig
));
// 设置最大连接数
connectionManager
.
setMaxTotal
(
100
);
// 整个连接池的最大连接数
connectionManager
.
setDefaultMaxPerRoute
(
20
);
}
catch
(
IOReactorException
e
)
{
throw
new
RuntimeException
(
e
);
}
PoolingNHttpClientConnectionManager
finalConnectionManager
=
connectionManager
;
RestClientBuilder
builder
=
RestClient
.
builder
(
esHosts
).
setRequestConfigCallback
(
requestConfigBuilder
->
{
requestConfigBuilder
.
setConnectTimeout
(
properties
.
getConnectionTimeout
());
requestConfigBuilder
.
setSocketTimeout
(
properties
.
getSocketTimeout
());
requestConfigBuilder
.
setConnectionRequestTimeout
(-
1
);
return
requestConfigBuilder
;
}).
setHttpClientConfigCallback
(
httpClientBuilder
->
{
httpClientBuilder
.
disableAuthCaching
();
httpClientBuilder
.
setMaxConnTotal
(
properties
.
getMaxConnTotal
());
httpClientBuilder
.
setMaxConnPerRoute
(
properties
.
getMaxConnPerRoute
());
return
httpClientBuilder
.
setDefaultCredentialsProvider
(
credentialsProvider
).
setConnectionManager
(
finalConnectionManager
);
});
return
new
RestHighLevelClient
(
builder
);
}
}
src/main/resources/application-option.properties
View file @
fb43340
...
...
@@ -3,13 +3,21 @@ server.port=12000
spring.jackson.time-
zone
=
GMT+8
spring.jackson.date-
format
=
yyyy-MM-dd HH:mm:ss
#es
spring.elasticsearch.rest.uris
=
http://1
92.168.1.106
:9200
spring.elasticsearch.rest.uris
=
http://1
82.92.184.40
:9200
spring.elasticsearch.rest.username
=
elastic
spring.elasticsearch.rest.password
=
viontech
spring.elasticsearch.rest.password
=
vion2021
spring.elasticsearch.rest.ioThreadCount
=
20
spring.elasticsearch.rest.maxConnTotal
=
100
spring.elasticsearch.rest.maxConnPerRoute
=
20
#\u5206\u7247\u6570\u91CF
vion.index.number_of_shards
=
1
#\u526F\u672C\u6570\u91CF
vion.index.number_of_replicas
=
0
vion.index.translog.durability
=
async
#??????
vion.index.refresh_interval
=
30s
vion.index.translog.sync_interval
=
30s
vion.index.merge.scheduler.max_thread_count
=
1
#delete-pool-after-days\u51E0\u5929\u540E\u5220\u9664\u5929\u6570\u914D\u7F6E
delete.after.days
=
5
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment