【问题标题】:How to monitor connection issues of Neo4j?如何监控 Neo4j 的连接问题?
【发布时间】:2018-06-29 13:31:37
【问题描述】:

我使用 Neo4j 社区版。要创建备份,我必须停止 Neo4j 进程,进行备份并再次启动该进程。我想为服务器端的数据库连接创建一个观察程序,以便向用户显示一些数据库不可用的警报消息。

我用的是驱动neo4j-javascript-driver

与其他数据库驱动程序类似,我认为 Neo4j 有类似的东西:

const driver = neo4j.driver('bolt://localhost', neo4j.auth.basic('neo4j', 'neo4j'));
const session = driver.session();

session.on('disconnect', () => console.log('disconnected'));

但是文档没有包含任何关于此的内容。如果 Neo4j 没有类似的东西,那么我想使用自定义 socket.io 连接连接到螺栓端口,例如:

const ioc = require('socket.io-client');

const NEO4J_BOLT_URL = 'https://localhost:7687';

const client = ioc.connect(NEO4J_BOLT_URL, {
  path: '/',
  transports: ['websocket'],
});

client.on('connect', () => console.log('connected'));
client.on('disconnect', () => console.log('disconnected'));

client.on('reconnect', () => console.log('reconnected'));
client.on('reconnect_error', (err) => console.log('attempt to reconnect has failed', err));

(它不起作用)

有人可以帮我在这个驱动程序中实现类似的东西吗?我需要的主要是 Neo4j 数据库是否存在时的回调。

【问题讨论】:

  • 我认为它肯定需要这样的功能。我打算运行一个非常简单的查询来检查数据库连接

标签: javascript node.js database neo4j bolt


【解决方案1】:

Neo4j 的驱动程序维护一个与数据库的连接池。

当您向驱动程序请求新会话时,驱动程序将从池中获取一个连接(或在需要时创建一个)。

没有connectdisconnect 事件。

您唯一能做的就是在执行事务时捕获错误并检查错误类型是否为SERVICE_UNAVAILABLE (https://neo4j.com/docs/api/javascript-driver/current/variable/index.html#static-variable-SERVICE_UNAVAILABLE)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-26
    • 2015-05-31
    • 2014-01-29
    • 1970-01-01
    相关资源
    最近更新 更多