gpt4 book ai didi

java - 地址必须解析,但没有解析 - InetSocketAddress#getAddress() 返回 null

转载 作者:行者123 更新时间:2023-11-30 06:00:36 24 4
gpt4 key购买 nike

当我启动通过elasticsearch java api 与ElasticSearch 5.6.10 交互的java 应用程序并且我的elasticsearch 集群有超过1 个节点时,我收到以下异常:

**

**Caused by: java.lang.IllegalArgumentException: Address must be resolved but wasn't - InetSocketAddress#getAddress() returned null
at org.elasticsearch.common.transport.InetSocketTransportAddress.<init>(InetSocketTransportAddress.java:48)
at com.intel.mar.data.elasticsearch.client.TransportClientFactory.createTransportClient(TransportClientFactory.java:30)
at com.intel.mar.service.config.ServiceConfig.serviceDataManager(ServiceConfig.java:81)
at com.intel.mar.service.config.ServiceConfig$$EnhancerBySpringCGLIB$$77f6a134.CGLIB$serviceDataManager$2(<generated>)
at com.intel.mar.service.config.ServiceConfig$$EnhancerBySpringCGLIB$$77f6a134$$FastClassBySpringCGLIB$$b506e141.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
at com.intel.mar.service.config.ServiceConfig$$EnhancerBySpringCGLIB$$77f6a134.serviceDataManager(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 40 more**

**

elasticsearch.yml

network.bind_host: 0.0.0.0
network.publish_host: "{{getenv "IP"}}"
path.data: /shared/el
cluster.name: "{{ getv (print "/solutions/" (getenv "COMPONENT_NAMESPACE") "/services/mar-server/es_cluster_name")}}"
cluster.routing.allocation.awareness.attributes: aws_zone_id
node.name: "{{getenv "ID"}}"
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: [{{getv (print "/solutions/" (getenv "COMPONENT_NAMESPACE") "/services/mar-server/elastic_search_seeds")}}]
discovery.zen.minimum_master_nodes: "{{getv (print "/solutions/" (getenv "COMPONENT_NAMESPACE") "/services/mar-server/es_minimum_master_nodes")}}"
http.cors.allow-origin: "/.*/"
http.cors.enabled: true

# AWS discovery

http.enabled: true
http.port: 9200

action.auto_create_index: true

transport.tcp.port: 9300
indices.fielddata.cache.size: 25%
script.inline: true
thread_pool.bulk.queue_size: 900

我通过以下方式创建elasticsearch java客户端:

    public Client createTransportClient() {
Settings settings = Settings.builder()
.put("cluster.name", config.db().clusterName())
.build();

return new PreBuiltTransportClient(settings)
.addTransportAddress(
new InetSocketTransportAddress(
new InetSocketAddress(
config.db().getElasticSearchHost(),
config.db().getElasticSearchNodePort()
)
)
);
}

最佳答案

问题在于 config.db().getElasticSearchHost() 返回由“,”分隔的主集群节点列表。解决方案如下:

Settings settings = Settings.builder()
.put("cluster.name", config.db().clusterName())
.build();

PreBuiltTransportClient preBuiltTransportClient = new PreBuiltTransportClient(settings);
String[] hosts = config.db().getElasticSearchHost().split(SPLIT_SEPARATOR);

for(int i=0; i<hosts.length;i++){
preBuiltTransportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hosts[i])
,config.db().getElasticSearchNodePort()));
}

return preBuiltTransportClient;

关于java - 地址必须解析,但没有解析 - InetSocketAddress#getAddress() 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52339646/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com