Created
October 10, 2016 13:11
-
-
Save MosesMansaray/45bd6276f6c071e821ff1e43b55d6355 to your computer and use it in GitHub Desktop.
TransportClient setup with Sniffing set to true to discover other nodes in the Elasticsearch cluster
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.euromoney.elasticsearch; | |
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; | |
import org.elasticsearch.client.transport.TransportClient; | |
import org.elasticsearch.common.settings.ImmutableSettings; | |
import org.elasticsearch.common.transport.InetSocketTransportAddress; | |
public class TransportClientSniffingTestMain { | |
public static void main(String[] args) throws InterruptedException { | |
TransportClient client = new TransportClient(ImmutableSettings.settingsBuilder() | |
.put("client.transport.sniff", true) // sniff the rest of cluster so we only need to set one ip | |
.put("cluster.name", "elasticsearch_sniff") | |
.put("client.transport.ping_timeout", "20s") | |
.put("client.transport.nodes_sampler_interval", "20s") | |
.build()); | |
client.addTransportAddress(new InetSocketTransportAddress("127.0.0.1", 9300)); | |
System.out.println("~~~~~~~~~ setup completed ~~~~~~~~~~~"); | |
System.out.println("~~~~~~~~~ sleeping for 1 second ~~~~~~~~~~~"); | |
Thread.sleep(1000); | |
ClusterHealthResponse clusterIndexHealths = client.admin().cluster().prepareHealth().get(); | |
// confirm we get info about the cluster and other nodes. | |
System.out.println("Cluster Name" + clusterIndexHealths.getClusterName()); | |
System.out.println("Number of Nodes" + clusterIndexHealths.getNumberOfNodes()); | |
System.out.println("String Printour" + clusterIndexHealths.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment