Created
February 19, 2017 02:37
-
-
Save DaddyMoe/0066f1d3191ed07d575545d7b2b8878d to your computer and use it in GitHub Desktop.
TransportClient setup with Sniffing set to true to discover other nodes in the Elasticsearch cluster Raw
This file contains 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