Зависимость Gradle:
Код: Выделить всё
implementation "com.oracle.database.spring:oracle-spring-boot-starter-aqjms:23.4.0"
Код: Выделить всё
@Configuration
@EnableJms
public class JmsConfiguration {
@Bean
public ConnectionFactory connectionFactory(DataSource dataSource) {
return AQjmsFactory.getQueueConnectionFactory(dataSource);
}
Код: Выделить всё
spring:
datasource:
url: jdbc:oracle:thin:@localhost:1521/ORCLPDB1
username: AQ_USER
password: your_password
oracleucp:
initial-pool-size: 5
min-pool-size: 10
max-pool-size: 30
connection-wait-timeout: 2 # 300 seconds
connection-factory-class-name: oracle.jdbc.pool.OracleDataSource
connection-pool-name: some_pool_name
type: oracle.ucp.jdbc.PoolDataSource
Код: Выделить всё
import jakarta.jms.ConnectionFactory;
import jakarta.jms.JMSException;
import oracle.jakarta.jms.AQjmsFactory;
import oracle.ucp.jdbc.PoolDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.annotation.EnableJms;
import java.sql.SQLException;
@Configuration
@EnableJms
public class JmsConfiguration {
@Bean
public ConnectionFactory connectionFactory(PoolDataSource poolDataSource) throws JMSException, SQLException {
poolDataSource.setInitialPoolSize(5);
poolDataSource.setMinPoolSize(10);
poolDataSource.setMaxPoolSize(30);
poolDataSource.setConnectionWaitTimeout(3000);
return AQjmsFactory.getQueueConnectionFactory(poolDataSource);
}
Код: Выделить всё
import oracle.ucp.jdbc.PoolDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.context.event.EventListener;
import java.sql.SQLException;
import java.util.List;
@SpringBootApplication
@ConfigurationPropertiesScan
public class RequestBufferingServiceApplication {
@Autowired
PoolDataSource poolDataSource;
public static void main(String[] args) {
SpringApplication.run(RequestBufferingServiceApplication.class, args);
}
@EventListener(ApplicationReadyEvent.class)
public void foo() throws SQLException {
System.out.println("------");
System.out.println("Available conn count: " + poolDataSource.getAvailableConnectionsCount());
System.out.println("Borrowed conn count: " + poolDataSource.getBorrowedConnectionsCount());
System.out.println("Init pool size: " + poolDataSource.getInitialPoolSize());
System.out.println("Min pool size: " + poolDataSource.getMinPoolSize());
System.out.println("Max pool size: " + poolDataSource.getMaxPoolSize());
System.out.println("ConnectionWaitTimeout: " + poolDataSource.getConnectionWaitTimeout());
System.out.println(poolDataSource.getStatistics());
System.out.println("------");
}
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... ction-pool
Мобильная версия