jdbc - Lagom Jdbc 读取端支持:com.typesafe.config.ConfigException$Missing:找不到密钥“slick.profile”的配置设置
问题描述
我正在尝试在 lagom 服务中设置 jdbc 读取端处理器:
class ProjectEventsProcessor(readSide: JdbcReadSide)(implicit ec: ExecutionContext) extends ReadSideProcessor[ProjectEvent] {
def buildHandler = {
readSide.builder[ProjectEvent]("projectEventOffset")
.setEventHandler[ProjectCreated]((conn: Connection, e: EventStreamElement[ProjectCreated]) => insertProject(e.event))
.build
}
private def insertProject(e: ProjectCreated) = {
Logger.info(s"Got event $e")
}
override def aggregateTags: Set[AggregateEventTag[ProjectEvent]] = ProjectEvent.Tag.allTags
}
服务在启动时连接到数据库正常
15:40:32.575 [info] play.api.db.DefaultDBApi [] - Database [default] connected at jdbc:postgresql://localhost/postgres?user=postgres
但就在这之后,我得到了例外。
com.typesafe.config.ConfigException$Missing:未找到密钥“slick.profile”的配置设置
首先,为什么这里会涉及到 slick?
我正在使用JdbcReadSide
但没有SlickReadSide
。
好的,假设 JdbcReadSide 在内部以某种方式使用 slick。
我已slick.profile
在我的服务的 application.config 中添加。
db.default.driver="org.postgresql.Driver"
db.default.url="jdbc:postgresql://localhost/postgres?user=postgres"
// Tried this way
slick.profile="slick.jdbc.PostgresProfile$"
// Also this fay (copied from play documentation).
slick.dbs.default.profile="slick.jdbc.PostgresProfile$"
slick.dbs.default.db.dataSourceClass = "slick.jdbc.DatabaseUrlDataSource"
slick.dbs.default.db.properties.driver = "org.postgresql.Driver"
但仍然得到这个异常。
到底是怎么回事?如何解决这个问题?
解决方案
根据docs,Lagom 使用akka-persistence-jdbc
,它在引擎盖下:
使用 Slick 映射表并管理 JDBC 调用的异步执行。
使用默认连接池(HikariCP)在application.conf
文件中设置的完整配置可能如下(主要从文档复制):
# Defaults to use for each Akka persistence plugin
jdbc-defaults.slick {
# The Slick profile to use
# set to one of: slick.jdbc.PostgresProfile$, slick.jdbc.MySQLProfile$, slick.jdbc.OracleProfile$ or slick.jdbc.H2Profile$
profile = "slick.jdbc.PostgresProfile$"
# The JNDI name for the Slick pre-configured DB
# By default, this value will be used by all akka-persistence-jdbc plugin components (journal, read-journal and snapshot).
# you may configure each plugin component to use different DB settings
jndiDbName=DefaultDB
}
db.default {
driver = "org.postgresql.Driver"
url = "jdbc:postgresql://localhost/postgres?user=postgres"
# The JNDI name for this DataSource
# Play, and therefore Lagom, will automatically register this DataSource as a JNDI resource using this name.
# This DataSource will be used to build a pre-configured Slick DB
jndiName=DefaultDS
# Lagom will configure a Slick Database, using the async-executor settings below
# and register it as a JNDI resource using this name.
# By default, all akka-persistence-jdbc plugin components will use this JDNI name
# to lookup for this pre-configured Slick DB
jndiDbName=DefaultDB
async-executor {
# number of objects that can be queued by the async executor
queueSize = 10000
# 5 * number of cores
numThreads = 20
# same as number of threads
minConnections = 20
# same as number of threads
maxConnections = 20
# if true, a Mbean for AsyncExecutor will be registered
registerMbeans = false
}
# Hikari is the default connection pool and it's fine-tuned to use the same
# values for minimum and maximum connections as defined for the async-executor above
hikaricp {
minimumIdle = ${db.default.async-executor.minConnections}
maximumPoolSize = ${db.default.async-executor.maxConnections}
}
}
lagom.persistence.jdbc {
# Configuration for creating tables
create-tables {
# Whether tables should be created automatically as needed
auto = true
# How long to wait for tables to be created, before failing
timeout = 20s
# The cluster role to create tables from
run-on-role = ""
# Exponential backoff for failures configuration for creating tables
failure-exponential-backoff {
# minimum (initial) duration until processor is started again
# after failure
min = 3s
# the exponential back-off is capped to this duration
max = 30s
# additional random delay is based on this factor
random-factor = 0.2
}
}
}
推荐阅读
- excel - EXCEL高亮其他表格中对应的行和列
- ios - 复制、粘贴和剪切对话框在 Flutter 中不适用于 iOS
- python - CS50 马里奥更感伤的 Python - 不打印行
- swift - 列表中的第一项始终被选中
- macos - iterm2+ohmyzsh:终端上的杂散字符来自上一个命令
- html - Bootstrap 5下划线默认更改?
- maven - Organisation-Wide repositories with GitHub Packages & Maven
- sql - SQL- How can I find the type for which maximum suicide cases have been registered for each state?
- javascript - How Can I Serve Static Content Alongside Dynamic Routes in A Deno Oak Server
- python - 如何从文件中删除空行/行?