Problem Statement
- We are using the Micronaut framework, and I want to override the default HikariCP connection pool, but it is not working. How can we achieve this?
- Alternatively, how can we close the default HikariCP connection pool in this framework? we have Implemented multi-tenancy and we have created Custom Hikari Cp for that !!
- The logging isn't functioning.
Micronaut version :- 3.7.4 database : PostgreSQl
Here is The Custom HikariCp for multi-tenancy Code
public DataSource createAndConfigureDataSource(String tenantName, String username, String password){
logger.info ("Creating a new DataSource for tenant "+tenantName );
HikariDataSource ds = new HikariDataSource();
ds.setUsername(username);
ds.setPassword(password);
ds.setJdbcUrl(MultiTenantConnectionProvider.DEFAULT_URL+tenantName) ;
ds.setDriverClassName("org.postgresql.Driver");
ds.setConnectionTimeout(20000);
// Minimum number of idle connections in the pool
ds.setMinimumIdle(2);
// Maximum number of actual connection in the pool
ds.setMaximumPoolSize(15);
ds.setSchema("public");
// Maximum time that a connection is allowed to sit idle in the pool
ds.setIdleTimeout(300000);
ds.setLeakDetectionThreshold(2100);
ds.setConnectionTimeout(20000);
// Setting up a pool name for each tenant datasource
String tenantConnectionPoolName = tenantName + " -connection-pool";
ds.setPoolName(tenantConnectionPoolName);
return ds;
}
Here is application.yml file code
datasources:
default:
driver-class-name: postgresDriver
db-type: postgres
dialect: POSTGRES
url: jdbc://postgesdatabse url
driverClassName: org.postgresql.Driver
username: ##
password: ##
hikari:
maximumPoolSize: 30
connectionTimeout: 30000
autocommit: false
maxLifetime: 30000
idleTimeout: 30000
minimumIdle: 3
log-connections: true
log-stack-traces: true
logging:
level:
com.zaxxer.hikari.HikariConfig: DEBUG
com.zaxxer.hikari: TRACE
Unable to find Solution!!