Spring boot application restarts on its own when Elastic search is down - spring

I have a spring boot application that is integrated with MySQL and Elastic Search. Most APIs connect directly with MySQL to fetch the data. Only 1 API fetch data from elastic search.
If Elastic Search goes down while the application is still running, the entire application tries to restart and fails since it is unable to connect with ES. When I checked the logs, I can see a lot of org.springframework.beans.factory.UnsatisfiedDependencyException error
#EnableElasticsearchRepositories declared on Application: Invocation
of init method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate
[org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository]:
Constructor threw exception; nested exception is
org.springframework.data.elasticsearch.UncategorizedElasticsearchException:
method [HEAD],
This causes the remaining APIs to be unavailable as well although they don't need Elastic Search to work. Is there a way to make sure the application stills runs fine even when the Elastic search is down? I did prefer to have only one API unavailable instead of the whole application going down

Related

"Not enough variable values available to expand" in Spring Cloud Config client app

I'm using Spring Cloud Config server.
In my Spring Boot client application a get an exception:
Caused by: java.lang.IllegalArgumentException: Not enough variable values available to expand 'oauth.auth-server-url'
This exception occurs for every remote JSON properties containing "/" like
"oauth.auth-server-url": "https://tokenmanager.mycompany/auth"
or
"oauth.auth-server-uri": "/openid/token"
Does anyone had the same problem?

how to use spring-data-elasticsearch in spring-boot starter 2.1.4?

How to use spring-data-elasticsearch in spring-boot 2.1.4 REALESE?
Current Error.
ERROR: org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{XGi_IpM0QHea4D3QbFbArQ}{HOST}{HOST:PORT}]]] with root cause
org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available:
My Environment.
elasticsearch 6.2.2
spring-boot 2.1.4 RELEASE(starter, spring-data-elasticsearch 3.1.4)
Hope.
spring-boot config elasticsearch client connection.
using application.yml's spring.elasticsearch.rest OR spring.data.elsticsearch
Can i use elasticsearch 6.2.2 in spring-boot 2.1.4 RELEASE(spring-data-elasticsearch 3.1.4)?
What should I do?
ERROR: org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{XGi_xxxxxxxxxxx}{HOST}{HOST:PORT}]]] with root cause
org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available:
There is a problem when connecting to Elasticsearch 6.2.2 on the srping-boot 2.1.4's spring-data-elasticsearch.
You are using tcp client for elasticsearch 6.2.2. No node available message comes from coordinate node when it does not find any available node to respond.
I would HIGHLY RECFOMMEND to go for Rest client. Why? Elasticsearch considering to remove tcp client from 7.0 version.
If you still considering tcp client:
2.1 set longer tcp client read time out;
2.2 Still getting error? Set your host to 0.0.0. (transport.host: 0.0.0.0) if it is localhost (127.0.0.0)
2.3 Still getting error? Enable the sniffer, sniffer checks available nodes and updates the node state, add to your config map .put("client.transport.sniff", true)
2.4 Set your all nodes as a master (I SOLVED MY ISSUE BY THIS)
2.5 (ADVENCED) If you are still getting this error, carefully read this blog and update system TCP keep alive time, https://blog.trifork.com/2015/04/08/dealing-with-nodenotavailableexceptions-in-elasticsearch/
One of the 2nd section items has to work. If doesnt work, please post your configuration and metrics (how many what kind of requests coming to ES, consider the queue size).
I hope this helps!

Spring Batch database Connection is not available, request timed out

During the work with Spring Batch for a project, I ran into the following problem. The project consists of:
a MySQL database (mysqld 10.2.13-MariaDB)
Spring Boot (2.1.1.RELEASE)
Spring Batch (4.1.0.RELEASE)
Spring Batch is configured to use the same datasource as the business logic for the JobRepository
The hikari connection pool size for the datasource is configured to have a size of 4 (which is the default when pusing the app to our CloudFoundry instance and injected during the auto-reconfiguration of Spring)
As a reference you can take a look into the sample project where I created a minimal project to reproduce the problem:
https://github.com/FlorianSW/spring-batch-connection-issue
The problem:
Given you've a controller, which handles one RequestMapping in which at least two things happen: The controller does an arbitrary action agains the business model database schema (e.g. saving or requesting an entity from the database) and afterwards starting a Spring Batch job through a call to JobLauncher#run. Spring Batch is configured to run the tasks asynchronous with a ThreadPoolTaskExecutor with the pool size of 1.
This works pretty fine, if the request mapping is queries only few times per second (round about 1-3 times). However, if the mapping is queried more than that, let's say 4+ (during testing I used 4 and up to 20 requests) times in a synchronized way (if testing locally), then the requests run into a deadlock, where some of them will be aborted with the following exception:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: Could not obtain last_insert_id(); nested exception is java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 5001ms.]
This problem can be mitigated when increasing the size of the connection pool to at least 7 (I don't know where this number could come from). After restarting the application and executing my test JavaScript code[1] to dispatch a number of requests I can easily increase the number of fetch requests to 150 and the application will handle these requests without any problems (as expected). Where, before increasing the pool size, numerous requests run into an timeout.
I'm not sure, if this qualifies as a bug or as an Improvement or whatever, and I'm not sure if the component is the documentation or something like that, however, my intention of this issue is:
Finding out, if Spring Batch, together with Spring Boot, requires a minimum number of available connections in the DB connection pool? If so, should this be mentioned in the documentation?
Or, if this is a bug as the JDBC connections used during the request processing are not returned to the pool in a reasonable short amount of time?
[1]
for (i = 0; i <= 150; i++) {fetch('http://localhost:8080/api/jobs/' + i, {method: 'PUT'})}

JDBC Postgres in Spring Application

New to spring. Trying to establish postgres connection in spring framework using Java. Eclipse is the editor tool.
Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [org.postgresql.Driver]
I have given the connector in build paths etc. Please help.
Not able to figure out what is the issue!

The 'real-time' search isn't supported because of the infinite Splunk Job nature

I am getting the following error when executing the real time search via Spring Splunk inbound adapter.
SEVERE: org.springframework.messaging.MessagingException: search Splunk data failed; nested exception is java.lang.UnsupportedOperationException: The 'real-time' search isn't supported because of the infinite Splunk Job nature.
Can anybody let me know how to execute real-time search from Spring application?
You need to set the mode in your XML config:
mode="REALTIME"

Resources