How spring cloud defines validation interval under the Pivotal Cloud Foundry?

柔情痞子 提交于 2019-12-13 03:04:52

问题


I'm working on application that get the DS from PCF (Pivotal Cloud FoundrY) User provided services. It's working properly but I want to understand how the validation interval is defined.

As Spring and PCF are managing my connection pool. I'd like to understand how that works.

public DataSource getProfileDS() {    
     PoolConfig poolConfig = new PoolConfig(5, 10, 30000);
     DataSourceConfig dsConfig = new DataSourceConfig(poolConfig, null);
     return connectionFactory().dataSource("profileDS", dsConfig);
}

Also, is there any way to set up the validation interval by my own like we are used to do under the tomcat?


回答1:


How spring cloud defines validation interval under the Pivotal Cloud Foundry?

Spring Cloud Config will define a validation query that is appropriate for your relational database.

Examples:

  • MySQL
  • Oracle
  • Postgres

As to the validation interval, it does not look like that's being configured. Instead, the DBCP-like pools use testOnBorrow, and Hikari is configured to use connectionTestQuery. When testing before obtaining a connection from the pool, setting the validation interval is unnecessary.

Also, is there any way to set up the validation interval by my own like we are used to do under the tomcat?

Not if you're going to use Spring Cloud Connectors, but you don't have to use Spring Cloud Connectors. There's a couple of other ways you can do this.

  • Spring Boot exposes VCAP_SERVICES as properties like vcap.services.<name>.credentials.username. You could use those to manually define a DataSource. See here.
  • You can use the new java-cfenv library, which is intended to complement Spring Boot better.

Hope that helps!



来源:https://stackoverflow.com/questions/56239718/how-spring-cloud-defines-validation-interval-under-the-pivotal-cloud-foundry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!