Pessoa, estou com um problema de conexão em meu microsserviço com o ActiveMQ, quando faço um teste com várias requisições, muitas conexões são abertas, no entanto não conseguem ser fechadas para dar espaço a novas, isso resulta em N conexoes sem uso ao longo do tempo, prejudicando a performance e estabilidade da API.
Segue factory de conexão com o activeMq
@Configuration
@EnableJms
@EnableAsync
public class FactoryActivyMqConfig {
@Value("${spring.activemq.broker-url}")
private String brokerUrl;
@Value("${spring.activemq.user}")
private String brokerUsername;
@Value("${spring.activemq.password}")
private String brokerPassword;
@Value("${application.thread.corePoolSize}")
private Integer corePoolSize;
@Value("${application.thread.maxPoolSize}")
private Integer maxPoolSize;
@Value("${application.thread.queueCapacity}")
private Integer queueCapacity;
@Value("{spring.application.name}")
private String applicationName;
private static final Logger LOGGER = LoggerFactory.getLogger(FactoryActivyMqConfig.class);
public ActiveMQConnectionFactory connectionFactory() {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUsername, brokerPassword, brokerUrl);
Properties props = new Properties();
props.put("FifoQueue", "true");
connectionFactory.setProperties(props);
return connectionFactory;
}
@Bean
public CachingConnectionFactory cachingConnectionFactory() {
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(connectionFactory());
return cachingConnectionFactory;
}
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory());
return factory;
}
@Bean
public JmsTemplate jmsTemplate() {
JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory());
return jmsTemplate;
}
@Bean(name = "taskExecutor")
public Executor taskExecutor() {
LOGGER.debug("Cria executor assincrono");
final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(corePoolSize);
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
executor.setThreadNamePrefix("BoletoThread-");
executor.initialize();
return executor;
}
}
Multhread ActiveMQ no aplication.properties
spring.activemq.pool.enabled=${ENV_AMQ_POOL_ENABLED:true}
spring.activemq.pool.max-connections=${ENV_AMQ_POOL_MAXCONNECTION:100}
spring.activemq.pool.reconnect-on-exception=${ENV_AMQ_POOL_RECONNECT:true}
Aparentemente local funciona, no entanto quando sobe no ambiente do cliente, o problema surge.