ElasticSearch(一) Transport Client


Transport  Client 通過遠程連接到Es 集群,他不加入集群,只是通過集群nodes 的 transportAddress 和集群通信。

一  如何通過集群域名獲得集群nodes的transportAddress

http://xxx.com/_cat/nodes?h=ip,port

http://xxx.com/_nodes/transport

 

二 TransportClient 初始化方式

// on startup

TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
        .addTransportAddress(new TransportAddress(InetAddress.getByName("host1"), 9300)) //9300 為nodes 默認的端口,請使用實際 端口號
        .addTransportAddress(new TransportAddress(InetAddress.getByName("host2"), 9300));

// on shutdown

client.close();

三 TransportClient 動態加入node

Settings settings = Settings.builder()
        .put("client.transport.sniff", true)   //嗅探 默認每5s去更新下集群新的節點,加入新節點,去掉壞節點
.put("cluster.name", "myClusterName") //集群名稱
.build();

TransportClient client = new PreBuiltTransportClient(settings);

四 Settings 其他參數

可通過設置 client.transport.nodes_sampler_interval 來改變輪詢集群節點連接的頻率。
Parameter Description

client.transport.ignore_cluster_name

Set to true to ignore cluster name validation of connected nodes. (since 0.19.4)

client.transport.ping_timeout

The time to wait for a ping response from a node. Defaults to 5s.

client.transport.nodes_sampler_interval

How often to sample / ping the nodes listed and connected. Defaults to 5s.


官方文檔:https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM