How to keep database active in spring boot application - java

We are using spring boot, apache camel and multiple datasources.
spring boot version: 1.5.9 release
primary database: postgres
Secondary database:oracle
We have deployed spring boot jar in linux server.
Datasource properties for postgres is
x.datasource.url=
x.datasource.username=
x.datasource.password=
x.data.jpa.repositories.enabled=true
datasource properties for oracle
y.datasource.url=
y.datasource.username=
y.datasource.password=
y.data.jpa.repositories.enabled=true
when application keeps ideal and After some times we are trying first request failed and getting error jdbc connection failed but it is working in second request without restarting.
please let me know how to keep database active.

You can use hikari connection pool. Refer to this on how to implement. You can configure no. of connections you want to keep with db

Related

How to handle configuration When Spring Boot config server itself is down?

I'm new to the spring cloud config server. Consider a scenario where we have 10 spring boot microservice fetching configurations from the Spring Boot Cloud Config. I was wondering How the 10 spring boot microservices will work when the Spring Boot Cloud Config itself is down?
Can someone answer to below queries:
If the config server is down, Will there be downtime for all the microservice connected to it?
Let's say we have a config file application.properties in GitHub and Spring boot config refers to the application.properties file in GitHub What if the username and password to access the application.properties file itself will change?
In terms of Disaster recovery, Do we need any backup of the config server? If yes, How can we achieve the same?
If the config server is down, Will there be downtime for all the microservice connected to it?
In real world application, there will be multiple instances of your config server deployed across multiple availability zones, fronted by load balancer or API gateway, or even you can register your multiple instance with eureka server so that there is No single point of failure.
So how the configuration will look like is instance 1 is in us-east-1
instance 2 in us-west-2, so even if one AZ is down it will not impact your services.
As far as GitHub or external repo is concerned, you can configure config server to read properties natively but that not something I will suggest !!
Let's say we have a config file application.properties in GitHub and Spring boot config refers to the application.properties file in GitHub What if the username and password to access the application.properties file itself will change?
First of all you should not commit password in Github for public repo, secondly password should be dynamically fetched from Idvault, or AWS secret Manager or other services whichever you prefer. So that even if you change password it will not affect any services.
In terms of Disaster recovery, Do we need any backup of the config server? If yes, How can we achieve the same?
Config server is just reading properties/config from repo that you provide,so repository where your code is hosted is of importance to you. Github can take care of that for you !!

Analyzing the performance of SQL queries between OnPrem and AWS environment

I am working in modernizing an existing REST services and moving from OnPrem to AWS.
The legacy application
deployed in a OnPrem Liberty Server
MS SQL server DB was used.
Spring/Hibernate was the core technologies.
New Application Details :
Spring Boot deployed in the AWS environment in a docker container
Server-Tomcat embedded with the Spring boot.
Database is the existing MS Sql server and it is located OnPrem
Some queries which were earlier took less that 500ms to execute is now taking upto 2000ms. The queries,logic and other code related thigs are same between the legacy and the new application. We are not able to find why the queries are taking more time in this.
In the legacy application we had used the server.xml to configure the data source and in the new application we have configured the data source in the Spring boot application.properties . Below are the Datasource configurations:
Liberty Server datasource :
<dataSource id="Microsoft SQL Server JDBC Driver - DataSource - JVM3" jndiName="jdbc/xxx" containerAuthDataRef="yyy" statementCacheSize="50" isolationLevel="TRANSACTION_READ_COMMITTED">
<jdbcDriver libraryRef="MSSQLJDBCLib"/>
<properties.microsoft.sqlserver databaseName="dbName" serverName="servername.com" portNumber="9999" lockTimeout="2000" packetSize="4096" sendStringParametersAsUnicode="false" trustStorePassword="{xor}" beginTranForVendorAPIs="false" freeResourcesOnClose="false" jmsOnePhaseOptimization="false" reauthentication="false" preTestSQLString="SELECT 1" validateNewConnection="false" validateNewConnectionRetryInterval="3" errorDetectionModel="ExceptionMapping" nonTransactionalDataSource="false" name="Microsoft SQL Server JDBC Driver - DataSource - JVM3" enableMultithreadedAccessDetection="false" beginTranForResultSetScrollingAPIs="false" validateNewConnectionRetryCount="100" connectionSharing="1"/>
<connectionManager agedTimeout="-1" connectionTimeout="180" maxIdleTime="300" maxPoolSize="30" minPoolSize="0" reapTime="240" purgePolicy="FailingConnectionOnly"/>
</dataSource>
Spring Boot Datasource :
spring.datasource.url=jdbc:sqlserver://server.com:9999;databaseName=dBName
spring.datasource.hikari.maximumPoolSize=30
spring.datasource.hikari.poolName=SpringBootJPAHikariCP
spring.datasource.hikari.maxLifetime=2000000
spring.datasource.hikari.connectionTimeout=180000
What may be the other parameters which can impact the query performance between the old and the new application?
Note : The ping time between the AWS servers and the OnPrem db takes less than 2ms (very negligible).
The issue is fixed. All the queries which we made to the database were doing an Index scan instead of index seek. That is because we missed the sendStringParametersAsUnicode="false" parameter in the Connection JDBC url.
We changed the connection url to take the required parameters and the queries ran perfectly fine.
spring.datasource.url=jdbc:sqlserver://server.com:9999;databaseName=dBName;packetSize=4096;sendStringParametersAsUnicode=false

Spring boot with spring data neo4j, database access path

in spring boot application with spring data neo4j
https://spring.io/guides/gs/accessing-neo4j-data-rest/
I do not understand in which db is it access? I am running neo4j server with default db, I created nodes, but app did not find any data.
How I can change the path?

Sharing database connection pool between Spring Boot apps running Embedded Tomcat

My current production setup requires me to share Oracle database connection pools between multiple Spring Boot apps where each app runs via an embedded Tomcat instance.
What options do I have to share the database connection pool among these Spring Boot apps?
Is JNDI an option? If so, could someone explain how storing the connection pool details in say LDAP accessed via JNDI works?

Spring MVC application getting hung on server start up

I am trying to deploy my spring + Hibernate application on JBOSS. while i am starting the server, server start is getting hung. Last entry in the start up log is -
DEBUG: org.springframework.jdbc.datasource.DriverManagerDataSource - Creating new JDBC DriverManager Connection to [myDatabaseURL]
In my application there are around 80 hibernate mapping file. when I am removing all of them excluding one simple basic mapping file, application is able to connect to the DB.
I also try to connect to DB using PLSQL developer and I was able to connect. So in other words DB is working fine.
Any suggestion or pointer for debug ? What can be possible reasons which i am overlooking?
Thanks

Categories

Resources