I am trying to create a sample Spring Boot Application using spring data to connect to Elastic Cloud. The goal of this application is to evaluate the performance of Elastic Cloud against a specific load. I am basically trying to perform CRUD operation on this SB Application.
I see the below snippet on the Elastic cloud using the Transport Client but getting exception. I would like to know how i can connect Spring Boot to Elastic Cloud.
#Bean
public TransportClient elasticsearchSecuredClient() throws Exception {
Settings settings = Settings.builder()
.put("cluster.name", CLUSTER_NAME)
.put("xpack.security.transport.ssl.enabled", true)
.put("request.headers.X-Found-Cluster", CLUSTER_NAME)
.put("xpack.security.user", CREDENTIALS)
.build();
return new PreBuiltXPackTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress(CLUSTER_URL, 9343)));
Exception: failed to load elasticsearch nodes : org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available:
Related
My company has Elastic Search behind the REST endpoints /search and /count, but it hides the cluster nodes from access.
I could call those REST endpoints through Native DSL queries, but I don't want to create a lot of the boilerplate code that comes with creating queries and mapping responses, which is why I would like to use Spring Data Elastic Search to do a lot of that for me. I would like to know if it is possible to connect to Spring Data Elastic Search to an ES instance through a proxy REST endpoint, but based on the docs, it seems like Spring Data ES can only connect to the ES Instance. Has anyone else had this kind of need?
Spring Data Elasticsearch operates upon an Elasticsearch client that is connected to a single Elasticsearch node or a cluster.
You link to the documentation, Chapter Elasticsearch Clients. In this chapter, in the section Client Configuration you find the description how to configure a proxy:
ClientConfiguration clientConfiguration = ClientConfiguration.builder()
.connectedTo("localhost:9200", "localhost:9291")
.withProxy("localhost:8888")
.build();
I'm trying to see how to configure Client-Server with my Spring Boot application using Hazelcast on Kubernete, since we want to have the capability of sharing the cache between different Spring Boot applications (I'm already able to setup the Embedded distributed cache with Kubernetes - which is not what we need).
In case of Spring Boot single application(not on Kubernetes), its kind of easy where i will spin up a Server lets say with 'localhost' and also spin up the client connecting to localhost. Also i can have multiple instances(members) of Server which will form a Hazelcast Cluster.
However in case of Kubernetes, I know we need to have 2 different Spring Boot applications, one will act as a Server and others will be client accessing the cache, but want to know how the client would connect to the Server. Because in case of Spring we Autowire the HazelcastInstance, so how would i connect to the Server which is running in its own Kubernetes Pod ( and container).
There are a few deployment guides for Kubernetes here, and worked examples here & here.
If your server pods are joining, then you pretty much have it. A client uses the same discovery mechanism.
Add the hazelcast-kubernetes plugin to the client's pod, and set the configuration properties with the same values as you use on the server for namespace, dns, etc.
Thanks Neil. As you indicated its the same way i currently configured in embedded caching on Kubernetes. I'am using the Service-Name and namespace to discover and connect to the Server members from HazelcastClient instance.
This is from Client Spring Boot application's HazelcastConfiguration:
#Bean
public HazelcastInstance hazelcastInstance() {
final ClientConfig config = new ClientConfig();
config.setClusterName("cluster-name");
if (enableOnK8s) {
config.getNetworkConfig().getKubernetesConfig().setEnabled(true)
.setProperty("namespace", namespaceValue)
.setProperty("service-name", serviceName);
}
return HazelcastClient.newHazelcastClient(config);
}
And on Hazelcast Server Spring Boot application, configuration stays same as Embedded Hazelcast configuration.
There are some services which are hosted in internet. My application spring boot services are deployed in K8S cluster. The cluster is behind the corporate firewall. When the services which are deployed in the cluster tries to communicate with the services which are hosted in the internet i am OperationTimeOutException. The REST call happens through RestTemplate and in some cases it happens through feign. In either case it is not working.
When i started the micro service i have provided the java options where the proxy configuration is provided.
java -Dhttp.proxyHost= -Dhttp.proxyPort= -Dhttps.proxyHost= -Dhttps.proxyPort= myapp.jar
When i hard code the proxy while creating the RestTemplate as below,
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
InetSocketAddress address = new InetSocketAddress(host,portNr);
Proxy proxy = new Proxy(Proxy.Type.HTTP,address);
factory.setProxy(proxy);
restTemplate.setRequestFactory(factory);
the communication happens and the application is working as expected. Why the RestTemplate is not able to pick the proxy setting provided in Java options?
I dont want to hardcode the proxy in the code.
I have a Spring Boot Application which stores/retries data from Cassandra DB. But if Cassandra is not available, Spring application does not boot.
Here is my code - https://github.com/simplyatul/springcassandrajunit
I am playing around DemoTableRepo.java. If I comment out
#RepositoryDefinition(domainClass = DemoTable.class, idClass = String.class)
then Spring boot app starts w/o connecting to Cassandra, however when Repo is used on retrieve/store call it throws following exception
java.lang.IllegalArgumentException: Interface org.simplyatul.cassandrajunit.repository.DemoTableRepo must be annotated with #org.springframework.data.repository.RepositoryDefinition!
If I keep the following line commented
#RepositoryDefinition(domainClass = DemoTable.class, idClass = String.class)
then Spring boot app tries to connect to Cassandra on boot and fails to start.
I found similar links/Qs, but things are not working with the solutions provided. Am I missing anything? Thanks in advance.
How can we stop spring boot data cassandra from connecting to localhost?
How to load spring application context even if Cassandra down
I have created a spring boot application that uses spring boot starter data elasticsearch to connect to elasticsearch. I want to configure this application to setup connection pooling. How do I configure the application.properties to support it?
Old answer. Since Boot 2.2, the reactive client doesn't have these options.
From the docs:
spring.data.elasticsearch.properties.*= # Additional properties used to configure the client.
Though it does appear that the default TransportClient does pool connections anyway.