spring-xd job repository datasource enable oracle fast connection failover - java

In Spring-XD clustered environment, we are using Oracle as job repository datasource. Right now, this has been configured through servers.yml. But, we have to enable fast connection failover (FCF) for High availability (HA). Does current servers.yml support this? Or Is there a way to replace job repository data source with Oracle Pool DataSource with ONS configuration. Please advise me with any solution?

you should be able to configure your datasource like any spring datasource.
did you try configure the datasource like this http://docs.spring.io/spring-data/jdbc/docs/current/reference/html/orcl.failover.html ?
you have to include your configuration like
datasource:
url: jdbc:"jdbc:oracle:thin:#(description=(address_list=(address=(host=rac1)(protocol=tcp)(port=1521))(address=(host=rac2)(protocol=tcp)(port=1521)))(connect_data=(service_name=racdb1)))"
username: sa
password:
driverClassName: oracle.jdbc.driver.OracleDriver
validationQuery: select 1 from INFORMATION_SCHEMA.SYSTEM_USERS
fast-connection-failover-enabled:true
ONS-configuration="rac1:6200,rac2:6200"
Let me know if that works, I am curious :)

Related

Is there any way to timeout slow queries on application server

I am using MySQL DB and spring boot 2.0.0 deployed on tomcat server, is there any way I can timeout slow queries from my application server.
In hikari Connection Pool there is a property - maxLifetimeMs which you can manipulate in two different ways:
Adding values in property file :
spring:
hikari:
max-lifetime: 840000
Changing in the config :
final HikariDataSource dataSource;
config.setMaxLifetime(840000);
This will have set the maximum time taken out by a query. No query can run beyond the duration set by you.
For identification of slow query you need to integrate any APM tool with your application server

NO DATASOURCE SET Error in Spring Boot-JDBC TEMPLATE

When I am retrieving data from the oracle database in the Springboot project am getting a No Datasource Set error kindly help me on this. Refer logs to sort the issue and thanks in advance.
in your application.yaml you can put sopmething like this:
spring:
datasource:
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jdbc:sqlserver://localhost:1433;databaseName=MyDatabase;encrypt=false
username: sa
password: Passw0#rd
If you are using application.properties instead of yaml then u can change to have entries like below:
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=MyDatabase;encrypt=false
...
note that the driver and url values will have different values depending of your database provider. The example is for SQL Server
If you are trying to connect to an Oracle XE database instance then you don't specify the driver-class-name (remove that entry) and as url you can have url: jdbc:oracle:thin:#localhost:1521:XE

The easiest Junit test for connection to database in spring boot application

I started to write application with friend and I would like to write a simple test for database connection. He is owner of server so test will be red now of course but when he set up database and change url, password and username it should become green. I think if there is some simpler test than writing controller/service/repository and try to do some operation on it to check database connection.
All we have for now is spring boot app generated by spring initilizr and application.properties:
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.show-sql=true
spring.datasource.url=dummy_url
spring.datasource.username=dummy_username
spring.datasource.password=dummy_pass
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
Is it testable in this state or I must create fully operational endpoint and test it?
try looking into JHipster: https://www.jhipster.tech/
normally you can use a memory database like h2 for local and test environment ;)

Spring Boot application.yml set datasource property globally, being ignored

I have a Spring Boot 1.5 app which is configured with an application.yml file.
I need to manage the connection pool which is default - Tomcat.
The problem is that the application.yml has a datasources property for several datasources.
My global datasource.max-active=10 (UPDATE: datasource.tomcat.max-active=10 is ignored too) is being completely ignored (I created a test to see what datasource is being injected, and default maxActive in them is set to 100). I have to add it to every datasource separately to make the pool work the way I need it to.
The application.yml looks like this (this is only part of it), and it creates datasource with maxActive=10, but there is bunch of repetitions:
spring:
.... #bunch of stuff, deleted for simplicity
datasource: #Added by me, ignored by Spring
max-active: 10 #Added by me, ignored by Spring
datasources:
datasource1:
url: jdbc:mysql://url:port1
max-active: 10 #Added by me, works
datasource2:
url: jdbc:mysql://url:port2
max-active: 10 #Added by me, works
Question: what is the correct way to set the max-active property globally to avoid this repetition?
Thanks.
When you are using multiple data sources, spring boot does not provide a default data source auto-configuration. This also means you have to provide connection pool properties for each data source. I don't think it's possible to set it globally.
Instead, you can use the placeholder to set it once and use it everywhere.
custom:
max-active: 10
spring:
datasources:
datasource1:
url: jdbc:mysql://url:port1
max-active: ${custom.max-active}
datasource2:
url: jdbc:mysql://url:port2
max-active: ${custom.max-active}
You can find more info here: How to setup multiple connection pools when multiple datasources are used in Spring Boot?

Change number of connection to database generated by a spring boot project

I have generated a spring boot project using jHipster. I want to reduce the number of connections to the database so I have modified the application-prod.yml file by adding the maximumPoolSize tag like this
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=utf8&useSSL=false
username: root
password:
maximumPoolSize: 2
But when I try deploying the application I have 10 connections to the database. What am I doing wrong?
Thanks
With Spring Boot 1.4 the general properties have been reduced and moved to specific properties per DataSource provider (which is also explained in the reference guide and the release notes).
So instead of using spring.datasource.maximumPoolSize you should be using spring.datasource.hikari.maximumPoolSize
For a list of properties see the appendix.

Categories