fix: 优化elasticsearch 配置,解决I/O reactor问题。
This commit is contained in:
parent
e8af34995b
commit
557366a3ec
@ -9,6 +9,7 @@ import org.apache.http.client.CredentialsProvider;
|
||||
import org.apache.http.conn.ConnectionKeepAliveStrategy;
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
|
||||
import org.apache.http.impl.nio.reactor.IOReactorConfig;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestClientBuilder;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
@ -72,7 +73,12 @@ public class ElasticsearchConfig extends AbstractElasticsearchConfiguration {
|
||||
CredentialsProvider credentialsProvider) {
|
||||
httpClientBuilder
|
||||
.setKeepAliveStrategy(getConnectionKeepAliveStrategy())
|
||||
.setMaxConnPerRoute(10);
|
||||
.setMaxConnPerRoute(10)
|
||||
.setDefaultIOReactorConfig(
|
||||
IOReactorConfig
|
||||
.custom()
|
||||
.setIoThreadCount(Runtime.getRuntime().availableProcessors())
|
||||
.build());
|
||||
if (credentialsProvider != null) {
|
||||
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
|
||||
}
|
||||
|
@ -455,8 +455,9 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
|
||||
this.client.bulkAsync(request, RequestOptions.DEFAULT, new ActionListener<BulkResponse>() {
|
||||
@Override
|
||||
public void onResponse(BulkResponse bulkItemResponses) {
|
||||
if (bulkItemResponses.hasFailures()) {
|
||||
throw new RetryException("批量更新商品索引失败,es内容版本冲突");
|
||||
log.info("批量更新商品索引结果:{}", bulkItemResponses.buildFailureMessage());
|
||||
if (bulkItemResponses.hasFailures() && bulkItemResponses.getItems().length > 0) {
|
||||
throw new RetryException("批量更新商品索引失败," + bulkItemResponses.buildFailureMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user