2017-03-02 3 views
1

Ich benutze Spring Boot und verwenden Postgres, Hase mq und Deploying-Anwendung auf CF. Wir haben festgestellt, dass wir den Verbindungspool einstellen müssen. Wir haben festgestellt, dass wir unabhängig von der Konfiguration, die wir tun, auf CF maximal 4 Verbindungen haben können, nicht sicher, woher wir diese Nummer bekommen (wahrscheinlich etwas mit buildpack oder service config).Wolke Gießerei Frühjahr Boot Datenquelle Pool-Konfiguration

Um dies zu beheben, musste ich AbstractCloudConfig erweitern, und das ist Schmerz, wie es andere Auto-Konfiguration ausschaltet, so muss ich jetzt manuell Hatch mq Verbindung Fabrik konfigurieren :(. Ich habe unten Konfiguration, aber nicht sicher ist dies der richtige Weg

Frühling Boot-Version. 1.4

Bitte geben

package com.example; 

import javax.sql.DataSource; 

import org.springframework.beans.factory.annotation.Value; 
import org.springframework.cloud.config.java.AbstractCloudConfig; 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.context.annotation.Primary; 
import org.springframework.context.annotation.Profile; 

/** 
* If we need to modify some some custom service configuration on cloud foundry 
* e.g. setting up of connection pools. If we set normally and expose bean, it 
* will work fine on local machine. But as it will go to Cloud foundry it 
* somehow creates max 4 connections. (Not sure from where this number comes) 
* 
* Adding this configuration meaning we no longer want to leverage auto 
* configuration. As soon as Spring boot sees this bean in cloud profile it will 
* turn of auto configuration. Expectation is application is going to take care 
* of all configuration. This normally works for most of the applications. 
* 
* For more information read: https://github.com/dsyer/cloud-middleware-blog 
* https://docs.cloudfoundry.org/buildpacks/java/spring-service-bindings.html 
* 
* Hopefully future release of spring boot will allow us to hijack only 
* configuration that we want to do ourselves and rest will be auto 
* configuration specifically in context with CloudFoundry. 
* 
*/ 
@Configuration 
@Profile("cloud") 
public class CloudServicesConfig extends AbstractCloudConfig { 

    @Value("${vcap.services.postgres.credentials.jdbc_uri}") 
    private String postgresUrl; 

    @Value("${vcap.services.postgres.credentials.username}") 
    private String postgresUsername; 

    @Value("${vcap.services.postgres.credentials.password}") 
    private String postgresPassword; 

    @Value("${spring.datasource.driver-class-name}") 
    private String dataSourceDriverClassName; 

    @Primary 
    @Bean 
    public DataSource dataSource() { 
     org.apache.tomcat.jdbc.pool.DataSource dataSource = new org.apache.tomcat.jdbc.pool.DataSource(); 
     dataSource.setDriverClassName(dataSourceDriverClassName); 
     dataSource.setUrl(postgresUrl); 
     dataSource.setUsername(postgresUsername); 
     dataSource.setPassword(postgresPassword); 
     dataSource.setInitialSize(10); 
     dataSource.setMaxIdle(5); 
     dataSource.setMinIdle(5); 
     dataSource.setMaxActive(25); 
     return dataSource; 
    } 

    // You can add rest of services configuration below e.g. rabbit connection 
    // factory, redis etc to centralize services configuration for cloud. 
    // This example did not use profile but that is what you should use to 
    // separate out cloud vs local configuraion to help run on local etc. 

} 
+0

Gefunden diese: https://discuss.pivotal.io/hc/en-us/articles/221898227-Connection-pool-warning-message-maxIdle-is-larger-than-maxActive- setting-maxIdle-zu-4-gesehen-in-PCF-bereitgestellt-Spring-app und https://github.com/spring-cloud/spring-cloud-connectors/blob/master/spring-cloud-spring-service- connector/src/main/java/org/springframework/cloud/service/relational/DbcpLikePooledDataSourceCreator.java – user3444718

+0

Sie verwenden Fettglas oder .war – ams

+0

Glas, wie es Spring Boot ist! – user3444718

Antwort

1

Sie nicht, dass die Konfiguration alle brauchen nur die Poolgröße anpassen Sie sollten nur diese brauchen.. Code wie in gezeigt die documentation:

@Bean 
public DataSource dataSource() { 
    PoolConfig poolConfig = new PoolConfig(5, 30, 3000); 
    DataSourceConfig dbConfig = new DataSourceConfig(poolConfig, null); 
    return connectionFactory().dataSource(dbConfig); 
}