PSQLException: FATAL: 抱歉,已经有太多客户端 Akka HTTP
PSQLException: FATAL: sorry, too many clients already Akka HTTP
我有一个连接到 PostgreSQL 数据库的应用程序,API 和 Akka 流使用 Twitter4J 提取推文。提取的推文被写入数据库,然后使用 Slick 进行查询。使用 Akka HTTP,我创建了一个 API 来向数据库发送查询。所以我的问题是,在几次请求之后我得到了这个错误:
我不确定问题出在哪里以及为什么会发生,因为我正在关闭 Actor 系统。
object Main extends ApiRoute {
def main(args: Array[String]): Unit = {
implicit val system = ActorSystem()
implicit val materializer = ActorMaterializer()
implicit val executionContext = system.dispatcher
val twitterStream = TwitterStreamFilters.configureTwitterStream()
val counter = new Counter
twitterStream.addListener(counter)
val bindingFuture = Http().bindAndHandle(routes, "localhost", 8080)
println("Server started!")
StdIn.readLine()
bindingFuture
.flatMap(_.unbind())
.onComplete(_ => system.terminate())
}
和application.conf文件:
scalaxdb = {
dataSourceClass = "slick.jdbc.DatabaseUrlDataSource"
properties = {
driver = "org.postgresql.Driver"
url = "jdbc:postgresql://localhost/twitter2.0?user=user&password=password"
}
}
如有任何帮助,我将不胜感激!
可以试试下面的配置吗?
scalaxdb = {
dataSourceClass = "slick.jdbc.DatabaseUrlDataSource"
properties = {
driver = "org.postgresql.Driver"
url = "jdbc:postgresql://localhost/twitter2.0?user=user&password=password"
}
numThreads = 10
}
因此,对于 numThreads,我将连接数限制为 10。
您可能还应该显示与数据库通信的代码?
我有一个连接到 PostgreSQL 数据库的应用程序,API 和 Akka 流使用 Twitter4J 提取推文。提取的推文被写入数据库,然后使用 Slick 进行查询。使用 Akka HTTP,我创建了一个 API 来向数据库发送查询。所以我的问题是,在几次请求之后我得到了这个错误:
我不确定问题出在哪里以及为什么会发生,因为我正在关闭 Actor 系统。
object Main extends ApiRoute {
def main(args: Array[String]): Unit = {
implicit val system = ActorSystem()
implicit val materializer = ActorMaterializer()
implicit val executionContext = system.dispatcher
val twitterStream = TwitterStreamFilters.configureTwitterStream()
val counter = new Counter
twitterStream.addListener(counter)
val bindingFuture = Http().bindAndHandle(routes, "localhost", 8080)
println("Server started!")
StdIn.readLine()
bindingFuture
.flatMap(_.unbind())
.onComplete(_ => system.terminate())
}
和application.conf文件:
scalaxdb = {
dataSourceClass = "slick.jdbc.DatabaseUrlDataSource"
properties = {
driver = "org.postgresql.Driver"
url = "jdbc:postgresql://localhost/twitter2.0?user=user&password=password"
}
}
如有任何帮助,我将不胜感激!
可以试试下面的配置吗?
scalaxdb = {
dataSourceClass = "slick.jdbc.DatabaseUrlDataSource"
properties = {
driver = "org.postgresql.Driver"
url = "jdbc:postgresql://localhost/twitter2.0?user=user&password=password"
}
numThreads = 10
}
因此,对于 numThreads,我将连接数限制为 10。
您可能还应该显示与数据库通信的代码?