neo4j - 如何使用 java api 获取 Neo4j 集群状态
问题描述
我正在尝试使用 java API 查找 neo4j 集群运行状况。我看到 CLI CALL dbms.cluster.overview() 是否有任何等效的 java api
解决方案
1. 变体“Spring Boot”
如果您可以选择带有 Spring Data Neo4J 的 Spring Boot,您可以定义一个 DAO,它执行您的 cypher 语句并在自己的 QueryResult 类中接收结果。
1.1 一般查询DAO
@Repository
public interface GeneralQueriesDAO extends Neo4jRepository<String, Long> {
@Query("CALL dbms.cluster.overview() YIELD id, addresses, role, groups, database;")
ClusterOverviewResult[] getClusterOverview();
}
1.2 ClusterOverviewResult
@QueryResult
public class ClusterOverviewResult {
private String id; // This is id of the instance.
private List<String> addresses; // This is a list of all the addresses for the instance.
private String role; // This is the role of the instance, which can be LEADER, FOLLOWER, or READ_REPLICA.
private List<String> groups; // This is a list of all the server groups which an instance is part of.
private String database; // This is the name of the database which the instance is hosting.
// omitted default constructor as well getter and setter for clarity
}
1.3 程序流程
@Autowired
private GeneralQueriesDAO generalQueriesDAO;
[...]
ClusterOverviewResult[] clusterOverviewResult = generalQueriesDAO.getClusterOverview();
2.变体“没有弹簧”
如果没有 Spring Boot,粗略的过程可能是:
Session session = driver.session();
StatementResult result = session.run("Cypher statement");
3.变体“HTTP端点”
推荐阅读
- pandas - 如何匹配另一列上的列值以从另一列中获取值?
- .net - 如何用一种形式的asp核心插入不同的表
- python-3.x - Heroku push:“Git push Heroku master”和“Buildpack”失败-> Python
- python - 让 PyCharm 在项目路径中搜索文件
- python - 如何取消 BERT 代币?
- ajax - 链接点击更新数据
- r - R代码更改整个列的日期
- bigcommerce - 如何验证用户是否在自定义 API 中登录 BigCommerce?
- python - 在输入字母之前将字符串中的字母更改为大写和小写
- java - 如果我想做输出,Scanner/System.in 的模拟是什么?