Tomcat: Creating a connection pool for cloud API services

168 Views Asked by At

A Tomcat server worker thread replying to an incoming request must access at least one of several possible cloud API services (Google Cloud Storage in particular; non-modifying, that is, only performing Reads). Tomcat offers out-of-the-box pooling for JDBC and JNDI compatible DB's and services. What is the best strategy for pooling connections to multiple cloud services to be shared across worker threads?

2

There are 2 best solutions below

2
On BEST ANSWER

As you mentioned Tomcat allows defining JDBC/JNDI resources that can be used by web applications. If there is a JDBC driver available for the service you want to use then you can use the same approach. For example, a quick search for GCS JDBC driver returns this.

For pooling, you could define HikariCP as a tomcat resource and configure it to connect to GCS using the third-party driver using the driverClassName property.

Alternatively, applications can use the HTTP-based SDKs that cloud providers usually make available.

0
On

Your application access API over HTTP(S). The connection pooling must be performed at HTTP Client level.

If you're using Apache HTTPClient, there are examples of usage of pool.