如何修改akka-persistence-jdbc的JDBC连接池最大/最小连接数?配置无效求解
It sounds like you're hitting a common snag when tuning connection pools for Akka Persistence JDBC—let’s walk through why your settings aren’t taking effect and how to fix them.
1. Fix the Configuration Path Hierarchy
The most probable issue is that your config keys are missing the critical top-level akka.persistence prefix. Akka Persistence JDBC expects its settings to be nested under this root, so your current top-level jdbc-journal entries are being ignored by the library.
Correct Configuration Structure
Replace your existing config with this properly nested version:
akka.persistence.jdbc { journal { slick.db { maxConnections = 2 minConnections = 2 } } snapshot-store { slick.db { maxConnections = 2 minConnections = 2 } } read-journal { slick.db { maxConnections = 2 minConnections = 2 } } }
2. Verify Connection Pool Provider Compatibility
Akka Persistence JDBC relies on Slick, which defaults to HikariCP for connection pooling. Depending on your Slick version, you might need to use Hikari-specific keys instead of Slick’s generic ones if the latter don’t translate correctly:
- Slick’s
maxConnectionsmaps to Hikari’smaximumPoolSize - Slick’s
minConnectionsmaps to Hikari’sminimumIdle
If the generic settings still don’t work, try configuring Hikari directly:
akka.persistence.jdbc { journal { slick.db { dataSourceClass = "com.zaxxer.hikari.HikariDataSource" properties { maximumPoolSize = 2 minimumIdle = 2 # Add other Hikari settings like connectionTimeout if needed } } } # Repeat the above block for snapshot-store and read-journal }
3. Check for Unintended Configuration Overrides
It’s possible another configuration source is overriding your settings. Common culprits include:
- System properties passed at startup (e.g.,
-Dakka.persistence.jdbc.journal.slick.db.maxConnections=10) - Environment variables mapped to config keys
- Profile-specific config files (like
application-prod.conf) or dependencyreference.confentries
To debug this, enable Akka’s config logging at startup to see which values are actually loaded:
akka.log-config-on-start = on
When your app launches, it will print the full resolved configuration—look for the akka.persistence.jdbc.*.slick.db sections to confirm your settings are active.
4. Confirm Your Library Version
Older versions of Akka Persistence JDBC used different config structures (e.g., top-level jdbc-journal keys). If you’re on a 2.x+ version, the akka.persistence.jdbc root is required. Double-check your library version to ensure your config matches the expected structure for that release.
内容的提问来源于stack exchange,提问作者idoshamun

