Commit 20d83c89 authored by suhuiguang's avatar suhuiguang

1.升级适配redisxinttiao

parent fab8e387
...@@ -8,7 +8,6 @@ import org.apache.http.impl.client.BasicCredentialsProvider; ...@@ -8,7 +8,6 @@ import org.apache.http.impl.client.BasicCredentialsProvider;
import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder; import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -17,40 +16,39 @@ import java.util.Arrays; ...@@ -17,40 +16,39 @@ import java.util.Arrays;
@Configuration @Configuration
public class ElasticSearchClientConfig { public class ElasticSearchClientConfig {
@Value("${spring.elasticsearch.rest.uris}") @Value("${spring.elasticsearch.rest.uris}")
private String uris; private String uris;
@Value("${elasticsearch.username}") @Value("${elasticsearch.username}")
private String username; private String username;
@Value("${elasticsearch.password}") @Value("${elasticsearch.password}")
private String password; private String password;
@Bean @Bean(destroyMethod = "close")
@Qualifier("highLevelClient") public RestHighLevelClient restHighLevelClient() {
public RestHighLevelClient restHighLevelClient() { final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY,
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
new UsernamePasswordCredentials(username, password));
try { try {
HttpHost[] httpHosts = Arrays.stream(uris.split(",")).map(HttpHost::create).toArray(HttpHost[]::new); HttpHost[] httpHosts = Arrays.stream(uris.split(",")).map(HttpHost::create).toArray(HttpHost[]::new);
RestClientBuilder builder = RestClient.builder(httpHosts); RestClientBuilder builder = RestClient.builder(httpHosts);
builder.setHttpClientConfigCallback(httpClientBuilder -> { builder.setHttpClientConfigCallback(httpClientBuilder -> {
httpClientBuilder.disableAuthCaching(); httpClientBuilder.disableAuthCaching();
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}); });
// 该方法接收一个RequestConfig.Builder对象,对该对象进行修改后然后返回。 // 该方法接收一个RequestConfig.Builder对象,对该对象进行修改后然后返回。
builder.setRequestConfigCallback(requestConfigBuilder -> { builder.setRequestConfigCallback(requestConfigBuilder -> {
// 连接超时(默认为1秒) // 连接超时(默认为1秒)
return requestConfigBuilder.setConnectTimeout(5000 * 1000) return requestConfigBuilder.setConnectTimeout(5000 * 1000)
// 套接字超时(默认为30秒)//更改客户端的超时限制默认30秒现在改为100*1000分钟 // 套接字超时(默认为30秒)//更改客户端的超时限制默认30秒现在改为100*1000分钟
.setSocketTimeout(6000 * 1000); .setSocketTimeout(6000 * 1000);
}); });
return new RestHighLevelClient(builder); return new RestHighLevelClient(builder);
} catch (Exception e) { } catch (Exception e) {
throw new IllegalStateException("Invalid ES nodes " + "property '" + uris + "'", e); throw new IllegalStateException("Invalid ES nodes " + "property '" + uris + "'", e);
} }
} }
} }
...@@ -1324,12 +1324,6 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -1324,12 +1324,6 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
result.setTotal(totle); result.setTotal(totle);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally {
try {
restHighLevelClient.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
} }
return result; return result;
} }
......
...@@ -312,12 +312,6 @@ public class CylinderFillingRecordServiceImpl extends BaseService<CylinderFillin ...@@ -312,12 +312,6 @@ public class CylinderFillingRecordServiceImpl extends BaseService<CylinderFillin
result.setTotal(totle); result.setTotal(totle);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally {
try {
restHighLevelClient.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
} }
return result; return result;
......
...@@ -877,12 +877,6 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind ...@@ -877,12 +877,6 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind
result.setTotal(totle); result.setTotal(totle);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally {
try {
restHighLevelClient.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
} }
return result; return result;
......
...@@ -14,7 +14,7 @@ eureka.instance.ip-address=172.16.3.34 ...@@ -14,7 +14,7 @@ eureka.instance.ip-address=172.16.3.34
## ES properties: ## ES properties:
elasticsearch.username=elastic elasticsearch.username=elastic
elasticsearch.password=a123456 elasticsearch.password=a123456
spring.elasticsearch.rest.uris=http:/172.16.10.230:9200 spring.elasticsearch.rest.uris=http://172.16.10.230:9200
## unit(h) ## unit(h)
alertcall.es.synchrony.time=48 alertcall.es.synchrony.time=48
#redis properties: #redis properties:
......
...@@ -17,40 +17,40 @@ import java.util.Arrays; ...@@ -17,40 +17,40 @@ import java.util.Arrays;
@Configuration @Configuration
public class ElasticSearchClientConfig { public class ElasticSearchClientConfig {
@Value("${spring.elasticsearch.rest.uris}") @Value("${spring.elasticsearch.rest.uris}")
private String uris; private String uris;
@Value("${elasticsearch.username}") @Value("${elasticsearch.username}")
private String username; private String username;
@Value("${elasticsearch.password}") @Value("${elasticsearch.password}")
private String password; private String password;
@Bean @Bean(destroyMethod = "close")
@Qualifier("highLevelClient") @Qualifier("highLevelClient")
public RestHighLevelClient restHighLevelClient() { public RestHighLevelClient restHighLevelClient() {
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(username, password)); new UsernamePasswordCredentials(username, password));
try { try {
HttpHost[] httpHosts = Arrays.stream(uris.split(",")).map(HttpHost::create).toArray(HttpHost[]::new); HttpHost[] httpHosts = Arrays.stream(uris.split(",")).map(HttpHost::create).toArray(HttpHost[]::new);
RestClientBuilder builder = RestClient.builder(httpHosts); RestClientBuilder builder = RestClient.builder(httpHosts);
builder.setHttpClientConfigCallback(httpClientBuilder -> { builder.setHttpClientConfigCallback(httpClientBuilder -> {
httpClientBuilder.disableAuthCaching(); httpClientBuilder.disableAuthCaching();
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}); });
// 该方法接收一个RequestConfig.Builder对象,对该对象进行修改后然后返回。 // 该方法接收一个RequestConfig.Builder对象,对该对象进行修改后然后返回。
builder.setRequestConfigCallback(requestConfigBuilder -> { builder.setRequestConfigCallback(requestConfigBuilder -> {
// 连接超时(默认为1秒) // 连接超时(默认为1秒)
return requestConfigBuilder.setConnectTimeout(5000 * 1000) return requestConfigBuilder.setConnectTimeout(5000 * 1000)
// 套接字超时(默认为30秒)//更改客户端的超时限制默认30秒现在改为100*1000分钟 // 套接字超时(默认为30秒)//更改客户端的超时限制默认30秒现在改为100*1000分钟
.setSocketTimeout(6000 * 1000); .setSocketTimeout(6000 * 1000);
}); });
return new RestHighLevelClient(builder); return new RestHighLevelClient(builder);
} catch (Exception e) { } catch (Exception e) {
throw new IllegalStateException("Invalid ES nodes " + "property '" + uris + "'", e); throw new IllegalStateException("Invalid ES nodes " + "property '" + uris + "'", e);
} }
} }
} }
...@@ -1323,12 +1323,6 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -1323,12 +1323,6 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
result.setTotal(totle); result.setTotal(totle);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally {
try {
restHighLevelClient.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
} }
return result; return result;
} }
......
...@@ -315,12 +315,6 @@ public class CylinderFillingRecordServiceImpl extends BaseService<CylinderFillin ...@@ -315,12 +315,6 @@ public class CylinderFillingRecordServiceImpl extends BaseService<CylinderFillin
result.setTotal(totle); result.setTotal(totle);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally {
try {
restHighLevelClient.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
} }
return result; return result;
......
...@@ -947,12 +947,6 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind ...@@ -947,12 +947,6 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind
result.setTotal(totle); result.setTotal(totle);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally {
try {
restHighLevelClient.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
} }
return result; return result;
......
...@@ -14,7 +14,7 @@ eureka.instance.ip-address=172.16.3.34 ...@@ -14,7 +14,7 @@ eureka.instance.ip-address=172.16.3.34
## ES properties: ## ES properties:
elasticsearch.username=elastic elasticsearch.username=elastic
elasticsearch.password=a123456 elasticsearch.password=a123456
spring.elasticsearch.rest.uris=http:/172.16.10.230:9200 spring.elasticsearch.rest.uris=http://172.16.10.230:9200
## unit(h) ## unit(h)
alertcall.es.synchrony.time=48 alertcall.es.synchrony.time=48
#redis properties: #redis properties:
......
...@@ -8,7 +8,6 @@ import org.apache.http.impl.client.BasicCredentialsProvider; ...@@ -8,7 +8,6 @@ import org.apache.http.impl.client.BasicCredentialsProvider;
import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder; import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -17,39 +16,39 @@ import java.util.Arrays; ...@@ -17,39 +16,39 @@ import java.util.Arrays;
@Configuration @Configuration
public class ElasticSearchClientConfig { public class ElasticSearchClientConfig {
@Value("${spring.elasticsearch.rest.uris}") @Value("${spring.elasticsearch.rest.uris}")
private String uris; private String uris;
@Value("${elasticsearch.username}") @Value("${elasticsearch.username}")
private String username; private String username;
@Value("${elasticsearch.password}") @Value("${elasticsearch.password}")
private String password; private String password;
@Bean @Bean(destroyMethod = "close")
public RestHighLevelClient restHighLevelClient() { public RestHighLevelClient restHighLevelClient() {
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(username, password)); new UsernamePasswordCredentials(username, password));
try { try {
HttpHost[] httpHosts = Arrays.stream(uris.split(",")).map(HttpHost::create).toArray(HttpHost[]::new); HttpHost[] httpHosts = Arrays.stream(uris.split(",")).map(HttpHost::create).toArray(HttpHost[]::new);
RestClientBuilder builder = RestClient.builder(httpHosts); RestClientBuilder builder = RestClient.builder(httpHosts);
builder.setHttpClientConfigCallback(httpClientBuilder -> { builder.setHttpClientConfigCallback(httpClientBuilder -> {
httpClientBuilder.disableAuthCaching(); httpClientBuilder.disableAuthCaching();
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}); });
// 该方法接收一个RequestConfig.Builder对象,对该对象进行修改后然后返回。 // 该方法接收一个RequestConfig.Builder对象,对该对象进行修改后然后返回。
builder.setRequestConfigCallback(requestConfigBuilder -> { builder.setRequestConfigCallback(requestConfigBuilder -> {
// 连接超时(默认为1秒) // 连接超时(默认为1秒)
return requestConfigBuilder.setConnectTimeout(5000 * 1000) return requestConfigBuilder.setConnectTimeout(5000 * 1000)
// 套接字超时(默认为30秒)//更改客户端的超时限制默认30秒现在改为100*1000分钟 // 套接字超时(默认为30秒)//更改客户端的超时限制默认30秒现在改为100*1000分钟
.setSocketTimeout(6000 * 1000); .setSocketTimeout(6000 * 1000);
}); });
return new RestHighLevelClient(builder); return new RestHighLevelClient(builder);
} catch (Exception e) { } catch (Exception e) {
throw new IllegalStateException("Invalid ES nodes " + "property '" + uris + "'", e); throw new IllegalStateException("Invalid ES nodes " + "property '" + uris + "'", e);
} }
} }
} }
...@@ -1323,12 +1323,6 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -1323,12 +1323,6 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
result.setTotal(totle); result.setTotal(totle);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally {
try {
restHighLevelClient.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
} }
return result; return result;
} }
......
...@@ -313,12 +313,6 @@ public class CylinderFillingRecordServiceImpl extends BaseService<CylinderFillin ...@@ -313,12 +313,6 @@ public class CylinderFillingRecordServiceImpl extends BaseService<CylinderFillin
result.setTotal(totle); result.setTotal(totle);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally {
try {
restHighLevelClient.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
} }
return result; return result;
......
...@@ -878,12 +878,6 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind ...@@ -878,12 +878,6 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind
result.setTotal(totle); result.setTotal(totle);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
}finally {
try {
restHighLevelClient.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
} }
return result; return result;
......
...@@ -14,7 +14,7 @@ eureka.instance.ip-address=172.16.3.34 ...@@ -14,7 +14,7 @@ eureka.instance.ip-address=172.16.3.34
## ES properties: ## ES properties:
elasticsearch.username=elastic elasticsearch.username=elastic
elasticsearch.password=a123456 elasticsearch.password=a123456
spring.elasticsearch.rest.uris=http:/172.16.10.230:9200 spring.elasticsearch.rest.uris=http://172.16.10.230:9200
## unit(h) ## unit(h)
alertcall.es.synchrony.time=48 alertcall.es.synchrony.time=48
#redis properties: #redis properties:
......
...@@ -8,47 +8,47 @@ import org.apache.http.impl.client.BasicCredentialsProvider; ...@@ -8,47 +8,47 @@ import org.apache.http.impl.client.BasicCredentialsProvider;
import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder; import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import java.util.Arrays; import java.util.Arrays;
@Configuration @Configuration
public class ElasticSearchClientConfig { public class ElasticSearchClientConfig {
@Value("${spring.elasticsearch.rest.uris}") @Value("${spring.elasticsearch.rest.uris}")
private String uris; private String uris;
@Value("${elasticsearch.username}") @Value("${elasticsearch.username}")
private String username; private String username;
@Value("${elasticsearch.password}") @Value("${elasticsearch.password}")
private String password; private String password;
@Bean @Bean(destroyMethod = "close")
public RestHighLevelClient restHighLevelClient() { public RestHighLevelClient restHighLevelClient() {
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(username, password)); new UsernamePasswordCredentials(username, password));
try { try {
HttpHost[] httpHosts = Arrays.stream(uris.split(",")).map(HttpHost::create).toArray(HttpHost[]::new); HttpHost[] httpHosts = Arrays.stream(uris.split(",")).map(HttpHost::create).toArray(HttpHost[]::new);
RestClientBuilder builder = RestClient.builder(httpHosts); RestClientBuilder builder = RestClient.builder(httpHosts);
builder.setHttpClientConfigCallback(httpClientBuilder -> { builder.setHttpClientConfigCallback(httpClientBuilder -> {
httpClientBuilder.disableAuthCaching(); httpClientBuilder.disableAuthCaching();
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}); });
// 该方法接收一个RequestConfig.Builder对象,对该对象进行修改后然后返回。 // 该方法接收一个RequestConfig.Builder对象,对该对象进行修改后然后返回。
builder.setRequestConfigCallback(requestConfigBuilder -> { builder.setRequestConfigCallback(requestConfigBuilder -> {
// 连接超时(默认为1秒) // 连接超时(默认为1秒)
return requestConfigBuilder.setConnectTimeout(5000 * 1000) return requestConfigBuilder.setConnectTimeout(5000 * 1000)
// 套接字超时(默认为30秒)//更改客户端的超时限制默认30秒现在改为100*1000分钟 // 套接字超时(默认为30秒)//更改客户端的超时限制默认30秒现在改为100*1000分钟
.setSocketTimeout(6000 * 1000); .setSocketTimeout(6000 * 1000);
}); });
return new RestHighLevelClient(builder); return new RestHighLevelClient(builder);
} catch (Exception e) { } catch (Exception e) {
throw new IllegalStateException("Invalid ES nodes " + "property '" + uris + "'", e); throw new IllegalStateException("Invalid ES nodes " + "property '" + uris + "'", e);
} }
} }
} }
...@@ -1324,12 +1324,6 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -1324,12 +1324,6 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
result.setTotal(totle); result.setTotal(totle);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally {
try {
restHighLevelClient.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
} }
return result; return result;
} }
......
...@@ -314,12 +314,6 @@ public class CylinderFillingRecordServiceImpl extends BaseService<CylinderFillin ...@@ -314,12 +314,6 @@ public class CylinderFillingRecordServiceImpl extends BaseService<CylinderFillin
result.setTotal(totle); result.setTotal(totle);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally {
try {
restHighLevelClient.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
} }
return result; return result;
......
...@@ -876,12 +876,6 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind ...@@ -876,12 +876,6 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind
result.setTotal(totle); result.setTotal(totle);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally {
try {
restHighLevelClient.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
} }
return result; return result;
......
...@@ -15,7 +15,7 @@ eureka.instance.ip-address=172.16.3.34 ...@@ -15,7 +15,7 @@ eureka.instance.ip-address=172.16.3.34
## ES properties: ## ES properties:
elasticsearch.username=elastic elasticsearch.username=elastic
elasticsearch.password=a123456 elasticsearch.password=a123456
spring.elasticsearch.rest.uris=http:/172.16.10.230:9200 spring.elasticsearch.rest.uris=http://172.16.10.230:9200
## unit(h) ## unit(h)
alertcall.es.synchrony.time=48 alertcall.es.synchrony.time=48
#redis properties: #redis properties:
...@@ -27,6 +27,7 @@ spring.redis.lettuce.pool.max-active=200 ...@@ -27,6 +27,7 @@ spring.redis.lettuce.pool.max-active=200
spring.redis.lettuce.pool.max-wait=-1 spring.redis.lettuce.pool.max-wait=-1
spring.redis.lettuce.pool.max-idle=10 spring.redis.lettuce.pool.max-idle=10
spring.redis.lettuce.pool.min-idle=0 spring.redis.lettuce.pool.min-idle=0
spring.redis.mode=cluster
## emqx properties: ## emqx properties:
emqx.clean-session=false emqx.clean-session=false
......
...@@ -8,7 +8,6 @@ import org.apache.http.impl.client.BasicCredentialsProvider; ...@@ -8,7 +8,6 @@ import org.apache.http.impl.client.BasicCredentialsProvider;
import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder; import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -17,40 +16,39 @@ import java.util.Arrays; ...@@ -17,40 +16,39 @@ import java.util.Arrays;
@Configuration @Configuration
public class ElasticSearchClientConfig { public class ElasticSearchClientConfig {
@Value("${spring.elasticsearch.rest.uris}") @Value("${spring.elasticsearch.rest.uris}")
private String uris; private String uris;
@Value("${elasticsearch.username}") @Value("${elasticsearch.username}")
private String username; private String username;
@Value("${elasticsearch.password}") @Value("${elasticsearch.password}")
private String password; private String password;
@Bean @Bean(destroyMethod = "close")
@Qualifier("highLevelClient") public RestHighLevelClient restHighLevelClient() {
public RestHighLevelClient restHighLevelClient() { final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY,
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
new UsernamePasswordCredentials(username, password));
try { try {
HttpHost[] httpHosts = Arrays.stream(uris.split(",")).map(HttpHost::create).toArray(HttpHost[]::new); HttpHost[] httpHosts = Arrays.stream(uris.split(",")).map(HttpHost::create).toArray(HttpHost[]::new);
RestClientBuilder builder = RestClient.builder(httpHosts); RestClientBuilder builder = RestClient.builder(httpHosts);
builder.setHttpClientConfigCallback(httpClientBuilder -> { builder.setHttpClientConfigCallback(httpClientBuilder -> {
httpClientBuilder.disableAuthCaching(); httpClientBuilder.disableAuthCaching();
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}); });
// 该方法接收一个RequestConfig.Builder对象,对该对象进行修改后然后返回。 // 该方法接收一个RequestConfig.Builder对象,对该对象进行修改后然后返回。
builder.setRequestConfigCallback(requestConfigBuilder -> { builder.setRequestConfigCallback(requestConfigBuilder -> {
// 连接超时(默认为1秒) // 连接超时(默认为1秒)
return requestConfigBuilder.setConnectTimeout(5000 * 1000) return requestConfigBuilder.setConnectTimeout(5000 * 1000)
// 套接字超时(默认为30秒)//更改客户端的超时限制默认30秒现在改为100*1000分钟 // 套接字超时(默认为30秒)//更改客户端的超时限制默认30秒现在改为100*1000分钟
.setSocketTimeout(6000 * 1000); .setSocketTimeout(6000 * 1000);
}); });
return new RestHighLevelClient(builder); return new RestHighLevelClient(builder);
} catch (Exception e) { } catch (Exception e) {
throw new IllegalStateException("Invalid ES nodes " + "property '" + uris + "'", e); throw new IllegalStateException("Invalid ES nodes " + "property '" + uris + "'", e);
} }
} }
} }
...@@ -313,12 +313,6 @@ public class CylinderFillingRecordServiceImpl extends BaseService<CylinderFillin ...@@ -313,12 +313,6 @@ public class CylinderFillingRecordServiceImpl extends BaseService<CylinderFillin
result.setTotal(totle); result.setTotal(totle);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally {
try {
restHighLevelClient.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
} }
return result; return result;
......
...@@ -877,12 +877,6 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind ...@@ -877,12 +877,6 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind
result.setTotal(totle); result.setTotal(totle);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally {
try {
restHighLevelClient.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
} }
return result; return result;
......
...@@ -15,7 +15,7 @@ eureka.instance.ip-address=172.16.3.34 ...@@ -15,7 +15,7 @@ eureka.instance.ip-address=172.16.3.34
## ES properties: ## ES properties:
elasticsearch.username=elastic elasticsearch.username=elastic
elasticsearch.password=a123456 elasticsearch.password=a123456
spring.elasticsearch.rest.uris=http:/172.16.10.230:9200 spring.elasticsearch.rest.uris=http://172.16.10.230:9200
## unit(h) ## unit(h)
alertcall.es.synchrony.time=48 alertcall.es.synchrony.time=48
#redis properties: #redis properties:
......
...@@ -28,6 +28,10 @@ ...@@ -28,6 +28,10 @@
<artifactId>poi-ooxml</artifactId> <artifactId>poi-ooxml</artifactId>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
</exclusion> </exclusion>
<exclusion>
<groupId>com.yeejoin</groupId>
<artifactId>amos-component-security</artifactId>
</exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency> <dependency>
...@@ -65,6 +69,11 @@ ...@@ -65,6 +69,11 @@
<artifactId>logstash-logback-encoder</artifactId> <artifactId>logstash-logback-encoder</artifactId>
<version>6.3</version> <version>6.3</version>
</dependency> </dependency>
<dependency>
<groupId>com.yeejoin</groupId>
<artifactId>amos-component-security</artifactId>
<version>${amos.version.tzs}</version>
</dependency>
</dependencies> </dependencies>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment