Commit 79f5b9b3 by admin

客户端部分修改

parent 0230aed5
...@@ -10,7 +10,7 @@ public class Client { ...@@ -10,7 +10,7 @@ public class Client {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
try { try {
Socket socket = new Socket("192.168.0.245", 22222); Socket socket = new Socket("192.168.0.36", 22222);
System.out.println("客户端启动成功"); System.out.println("客户端启动成功");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter write = new PrintWriter(socket.getOutputStream()); PrintWriter write = new PrintWriter(socket.getOutputStream());
......
package com.zhiwei.util;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
/**
* es连接类
*
* @author shenjinzhu
*
*/
public class ESClient {
private static String esIp;
private static int esPort;
private static String clusterName;
private static class ESClientHolder {
static TransportClient client = initESClient();
private static TransportClient initESClient() {
esIp=Config.getVal("esIp");
clusterName=Config.getVal("clusterName");
esPort=Integer.valueOf(Config.getVal("esPort"));
Settings esSettings = Settings.builder().put("cluster.name", clusterName) // 设置ES实例的名称
// 自动嗅探整个集群的状态,把集群中其他ES节点的ip添加到本地的客户端列表中
.put("client.transport.sniff", false).build();
TransportClient client = new PreBuiltTransportClient(esSettings);
try {
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(esIp), esPort));
} catch (UnknownHostException e) {
e.printStackTrace();
}
return client;
}
}
public static TransportClient getInstance() {
return ESClientHolder.client;
}
}
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