Postgresql 获取PGConnection.getNotifications中的大小

Postgresql 获取PGConnection.getNotifications中的大小,postgresql,akka,scalikejdbc,Postgresql,Akka,Scalikejdbc,我的postgresql数据库中的函数在更新表时发送通知。 我通过scalikejdbc轮询postgresql数据库,以获取所有通知,然后对它们进行处理。 解释了该过程。典型的sql表更新反应式系统。 我从java.sql.Connection获取PGConnection。然后,我通过以下方式收到通知: val notifications = Option(pgConnection.getNotifications).getOrElse(Array[PGNotification]()) 我试

我的postgresql数据库中的函数在更新表时发送通知。 我通过scalikejdbc轮询postgresql数据库,以获取所有通知,然后对它们进行处理。 解释了该过程。典型的sql表更新反应式系统。 我从java.sql.Connection获取PGConnection。然后,我通过以下方式收到通知:

val notifications = Option(pgConnection.getNotifications).getOrElse(Array[PGNotification]())
我试图通过将fetch大小设置为1000,并禁用自动提交,以1000块的形式获取通知。但“获取大小”属性被忽略

你知道我该怎么做吗? 我不想在通知数据集上的一个映射中处理数十万个通知

pgConnection.getNotifications.size可能很大,因此,此代码无法很好地扩展


谢谢

>P>更好的规模,考虑使用和:前者是一个可以异步获得PostgreSQL通知的库,前者是提供背压的实现(这将避免寻呼的需要)。例如:

导入akka.actor_
导入akka.stream_
导入akka.stream.scaladsl_
导入com.github.mauricio.async.db.postgresql.PostgreSQLConnection
导入com.github.mauricio.async.db.postgresql.util.URLParser
导入scala.concurrent.duration_
导入scala.concurrent.Await
类DbActor(隐式物化器:ActorMaterializer)使用ActorLogging扩展了Actor{
私有隐式val ec=context.system.dispatcher
val队列=
Source.queue[String](Int.MaxValue,OverflowStrategy.backpressure)
.to(Sink.foreach(println))
.run()
val configuration=URLParser.parse(“jdbc:postgresql://localhost:5233/my_db?user=dbuser&password=pwd")
val连接=新的PostgreSQLConnection(配置)
等待结果(connection.connect,5秒)
connection.sendQuery(“监听我的频道”)
connection.registerNotifyListener{message=>
val msg=message.payload
debug(“发送有效负载:{}”,msg)
赛尔夫!味精
}
def接收={
案例有效负载:字符串=>
queue.offer(有效负载).pipeTo(self)
案例QueueOfferResult.Dropped=>
log.warning(“删除了一条消息”)
案例QueueOfferResult.Enqueued=>
debug(“将消息排入队列”)
案例QueueOfferResult.失败(t)=>
错误(“流失败:{}”,t.getMessage)
案例QueueOfferResult.QueueClosed=>
debug(“流已关闭”)
}
}
上面的代码只是在PostgreSQL发出通知时打印它们;您可以用另一个
Sink
替换
Sink.foreach(println)
。要运行它,请执行以下操作:

导入akka.actor_
导入akka.stream.Actormatarializer
对象示例扩展了应用程序{
隐式val system=ActorSystem()
隐式val-materializer=actormatarializer()
actorOf(Props(类[DbActor],物化器))
}

可能使用akka streams和
.group