从 Micronaut Java 应用访问 Heroku 上的 Neo4j/GrapheneDB(开发免费计划)失败:与数据库的连接终止

Accessing Neo4j/GrapheneDB (Dev free plan) on Heroku from Micronaut Java app fails: Connection to database terminated

目前我正在为 Heroku 平台上的 Neo4j/GrapheneDB(Dev 免费计划)苦苦挣扎。 通过 "heroku local" 在本地启动我的应用程序工作正常,它将 (Neo4j Java Driver 4) 连接到 Neo4j 3.5.18 (运行 from Docker image "neo4j:3.5") .

我的应用程序是使用 Micronaut 框架构建的,使用其 Neo4j support. Launching my app on Heroku platform succeeds, I'm using Gradle Heroku plugin 完成此任务。

但是通过业务操作(和健康检查)访问数据库失败,异常如下:

INFO  Driver - Direct driver instance 1523082263 created for server address hobby-[...]ldel.dbs.graphenedb.com:24787
WARN  RetryLogic - Transaction failed and will be retried in 1032ms
org.neo4j.driver.exceptions.ServiceUnavailableException: Connection to the database terminated. Please ensure that your database is listening on the correct host and port and that you have compatible encryption settings both on Neo4j server and driver. Note that the default encryption setting has changed in Neo4j 4.0.
 at org.neo4j.driver.internal.util.Futures.blockingGet(Futures.java:143)
 at org.neo4j.driver.internal.InternalSession.beginTransaction(InternalSession.java:163)
 at org.neo4j.driver.internal.InternalSession.lambda$transaction(InternalSession.java:147)
 at org.neo4j.driver.internal.retry.ExponentialBackoffRetryLogic.retry(ExponentialBackoffRetryLogic.java:101)
 at org.neo4j.driver.internal.InternalSession.transaction(InternalSession.java:146)
 at org.neo4j.driver.internal.InternalSession.readTransaction(InternalSession.java:112)
 at org.neo4j.driver.internal.InternalSession.readTransaction(InternalSession.java:106)
 at PersonController.logInfoOf(PersonController.java:57)
 at PersonController.<init>(PersonController.java:50)
 at $PersonControllerDefinition.build(Unknown Source)
 at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1814)
 [...]
 at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
 at java.base/java.lang.Thread.run(Thread.java:832)
Suppressed: org.neo4j.driver.internal.util.ErrorUtil$InternalExceptionCause: null
 at org.neo4j.driver.internal.util.ErrorUtil.newConnectionTerminatedError(ErrorUtil.java:52)
 at org.neo4j.driver.internal.async.connection.HandshakeHandler.channelInactive(HandshakeHandler.java:81)
 [...]
 at org.neo4j.driver.internal.shaded.io.netty.util.internal.ThreadExecutorMap.run(ThreadExecutorMap.java:74)
 at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
 ... 1 common frames omitted

我确定从 OS 环境变量 GRAPHENEDB_BOLT_URL、GRAPHENEDB_BOLT_USER 和 GRAPHENEDB_BOLT_PASSWORD 中获取登录凭据并正确注入到应用程序中;我已经用一些调试日志语句验证了它:

State changed from starting to up
INFO  io.micronaut.runtime.Micronaut - Startup completed in 2360ms. Server Running: http://localhost:7382
INFO  Application - Neo4j Bolt URIs: [bolt://hobby-[...]ldel.dbs.graphenedb.com:24787]
INFO  Application - Neo4j Bolt encrypted? false
INFO  Application - Neo4j Bolt trust strategy: TRUST_SYSTEM_CA_SIGNED_CERTIFICATES
INFO  Application - Changed trust strategy to: TRUST_ALL_CERTIFICATES
INFO  Application - Env.: GRAPHENEDB_BOLT_URL='bolt://hobby-[...]ldel.dbs.graphenedb.com:24787'
INFO  Application - Env.: GRAPHENEDB_BOLT_USER='app1[...]hdai'
INFO  Application - Env.: GRAPHENEDB_BOLT_PASSWORD of length 31

我也尝试通过 Heroku 插件网站重启 GrapheneDB 实例,但结果相同。

这里出了什么问题?有什么方法可以进一步确定根本原因吗?

谢谢

基督教徒

我仔细看了看,您似乎需要为 Graphene 数据库实例打开驱动程序加密。这可以在 application.yml 中配置如下:

neo4j:
    encryption: true

作为参考,这里有一个示例项目https://github.com/aldrinm/micronaut-neo4j-heroku