我正在尝试使用Java API查找neo4j集群的运行状况。我看到CLI CALL dbms.cluster.overview()是否有与此等效的Java api
答案 0 :(得分:0)
如果带有Spring Data Neo4J的Spring Boot是您的选择,则可以定义一个DAO,该DAO执行cypher语句并在自己的QueryResult类中接收结果。
@Repository
public interface GeneralQueriesDAO extends Neo4jRepository<String, Long> {
@Query("CALL dbms.cluster.overview() YIELD id, addresses, role, groups, database;")
ClusterOverviewResult[] getClusterOverview();
}
@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
}
@Autowired
private GeneralQueriesDAO generalQueriesDAO;
[...]
ClusterOverviewResult[] clusterOverviewResult = generalQueriesDAO.getClusterOverview();
没有Spring Boot,粗略的过程可能是:
Session session = driver.session();
StatementResult result = session.run("Cypher statement");
另一种选择是使用HTTP endpoints for monitoring the health of a Neo4j Causal Cluster。